/* This file is part of PacketDotNet PacketDotNet is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PacketDotNet is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with PacketDotNet. If not, see . */ /* * Copyright 2010 Evan Plaice */ using System; using PacketDotNet.Utils; namespace PacketDotNet.Tcp { /// /// A TCP Option /// public abstract class Option { #region Constructors /// /// Creates an Option from a byte[] /// /// /// A /// /// /// A /// /// /// A /// public Option(byte[] bytes, int offset, int length) { optionData = new ByteArraySegment(bytes, offset, length); } #endregion #region Properties /// /// The Length of the Option type /// public virtual byte Length { get { return Bytes[LengthFieldOffset]; } } /// /// The Kind of option /// public OptionTypes Kind { get { return (OptionTypes)Bytes[KindFieldOffset]; } } /// /// Returns a TLV that contains the Option /// public byte[] Bytes { get { byte[] bytes = new byte[optionData.Length]; Array.Copy(optionData.Bytes, optionData.Offset, bytes, 0, optionData.Length); return bytes; } } #endregion #region Methods /// /// Returns the Option info as a string /// /// /// A /// public override string ToString() { return "[" + Kind.ToString() + "]"; } #endregion #region Members // stores the data/length/offset of the option private ByteArraySegment optionData; /// The length (in bytes) of the Kind field internal const int KindFieldLength = 1; /// The length (in bytes) of the Length field internal const int LengthFieldLength = 1; /// The offset (in bytes) of the Kind Field internal const int KindFieldOffset = 0; /// The offset (in bytes) of the Length field internal const int LengthFieldOffset = 1; #endregion } }