Permalink
Browse files

added new files in updated Libraries (missing in earlier git commit)

  • Loading branch information...
1 parent e230750 commit 6480f939d354f250daf200208f750bacde94d0e0 @seuffert committed Feb 23, 2011
Showing with 11,991 additions and 0 deletions.
  1. +309 −0 PacketDotNet/Ieee80211FrameControlField.cs
  2. +50 −0 PacketDotNet/Ieee80211MacFields.cs
  3. +362 −0 PacketDotNet/Ieee80211MacFrame.cs
  4. +70 −0 PacketDotNet/Ieee80211RadioFields.cs
  5. +233 −0 PacketDotNet/Ieee80211RadioPacket.cs
  6. +50 −0 PacketDotNet/Ieee80211RadioTapChannelFlags.cs
  7. +704 −0 PacketDotNet/Ieee80211RadioTapFields.cs
  8. +52 −0 PacketDotNet/Ieee80211RadioTapFlags.cs
  9. +176 −0 PacketDotNet/Ieee80211RadioTapType.cs
  10. +42 −0 PacketDotNet/StringOutputType.cs
  11. +96 −0 PacketDotNet/Tcp/AlternateChecksumData.cs
  12. +90 −0 PacketDotNet/Tcp/AlternateChecksumRequest.cs
  13. +47 −0 PacketDotNet/Tcp/ChecksumAlgorighmType.cs
  14. +53 −0 PacketDotNet/Tcp/Echo.cs
  15. +57 −0 PacketDotNet/Tcp/EchoReply.cs
  16. +78 −0 PacketDotNet/Tcp/EndOfOptions.cs
  17. +96 −0 PacketDotNet/Tcp/MD5Signature.cs
  18. +91 −0 PacketDotNet/Tcp/MaximumSegmentSize.cs
  19. +78 −0 PacketDotNet/Tcp/NoOperation.cs
  20. +118 −0 PacketDotNet/Tcp/Option.cs
  21. +111 −0 PacketDotNet/Tcp/OptionTypes.cs
  22. +117 −0 PacketDotNet/Tcp/SACK.cs
  23. +57 −0 PacketDotNet/Tcp/SACKPermitted.cs
  24. +104 −0 PacketDotNet/Tcp/TimeStamp.cs
  25. +112 −0 PacketDotNet/Tcp/UserTimeout.cs
  26. +94 −0 PacketDotNet/Tcp/WindowScaleFactor.cs
  27. +338 −0 PacketDotNet/WakeOnLanPacket.cs
  28. +66 −0 SharpPcap/AirPcap/AirPcapAdapterBus.cs
  29. +60 −0 SharpPcap/AirPcap/AirPcapAdapterId.cs
  30. +40 −0 SharpPcap/AirPcap/AirPcapBands.cs
  31. +87 −0 SharpPcap/AirPcap/AirPcapChannelInfo.cs
  32. +48 −0 SharpPcap/AirPcap/AirPcapChannelInfoFlags.cs
  33. +40 −0 SharpPcap/AirPcap/AirPcapDecryptionState.cs
  34. +973 −0 SharpPcap/AirPcap/AirPcapDevice.cs
  35. +104 −0 SharpPcap/AirPcap/AirPcapDeviceCapabilities.cs
  36. +60 −0 SharpPcap/AirPcap/AirPcapDeviceDescription.cs
  37. +230 −0 SharpPcap/AirPcap/AirPcapDeviceList.cs
  38. +58 −0 SharpPcap/AirPcap/AirPcapDeviceTimestamp.cs
  39. +79 −0 SharpPcap/AirPcap/AirPcapKey.cs
  40. +45 −0 SharpPcap/AirPcap/AirPcapKeyType.cs
  41. +50 −0 SharpPcap/AirPcap/AirPcapLinkTypes.cs
  42. +1 −0 SharpPcap/AirPcap/AirPcapMacFlags.cs
  43. +40 −0 SharpPcap/AirPcap/AirPcapMediumType.cs
  44. +104 −0 SharpPcap/AirPcap/AirPcapPacketHeader.cs
  45. +793 −0 SharpPcap/AirPcap/AirPcapSafeNativeMethods.cs
  46. +83 −0 SharpPcap/AirPcap/AirPcapStatistics.cs
  47. +310 −0 SharpPcap/AirPcap/AirPcapUnmanagedStructures.cs
  48. +40 −0 SharpPcap/AirPcap/AirPcapValidationType.cs
  49. +69 −0 SharpPcap/AirPcap/AirPcapVersion.cs
  50. +32 −0 SharpPcap/AirPcap/Win32SafeNativeMethods.cs
  51. +205 −0 SharpPcap/CaptureDeviceList.cs
  52. +193 −0 SharpPcap/ICaptureDevice.cs
  53. +45 −0 SharpPcap/ICaptureStatistics.cs
  54. +40 −0 SharpPcap/InvalidOperationDuringBackgroundCaptureException.cs
  55. +253 −0 SharpPcap/LibPcap/LibPcapLiveDevice.cs
  56. +232 −0 SharpPcap/LibPcap/LibPcapLiveDeviceList.cs
  57. +205 −0 SharpPcap/LibPcap/LibPcapSafeNativeMethods.cs
  58. +128 −0 SharpPcap/LibPcap/OfflinePcapDevice.cs
  59. +92 −0 SharpPcap/LibPcap/PcapAddress.cs
  60. +631 −0 SharpPcap/LibPcap/PcapDevice.cs
  61. +410 −0 SharpPcap/LibPcap/PcapDeviceCaptureLoop.cs
  62. +172 −0 SharpPcap/LibPcap/PcapHeader.cs
  63. +182 −0 SharpPcap/LibPcap/PcapInterface.cs
  64. +128 −0 SharpPcap/LibPcap/PcapStatistics.cs
  65. +293 −0 SharpPcap/LibPcap/PcapUnmanagedStructures.cs
  66. +173 −0 SharpPcap/LibPcap/Sockaddr.cs
  67. +40 −0 SharpPcap/OfflineCaptureDevice.cs
  68. +40 −0 SharpPcap/WinPcap/AuthenticationTypes.cs
  69. +42 −0 SharpPcap/WinPcap/CaptureMode.cs
  70. +57 −0 SharpPcap/WinPcap/OpenFlags.cs
  71. +70 −0 SharpPcap/WinPcap/RemoteAuthentication.cs
  72. +194 −0 SharpPcap/WinPcap/SafeNativeMethods.cs
  73. +197 −0 SharpPcap/WinPcap/SendQueue.cs
  74. +41 −0 SharpPcap/WinPcap/SendQueueTransmitModes.cs
  75. +58 −0 SharpPcap/WinPcap/StatisticsModeEventArgs.cs
  76. +31 −0 SharpPcap/WinPcap/StatisticsModeEventHandler.cs
  77. +74 −0 SharpPcap/WinPcap/StatisticsModePacket.cs
  78. +40 −0 SharpPcap/WinPcap/UnmanagedStructures.cs
  79. +269 −0 SharpPcap/WinPcap/WinPcapDevice.cs
  80. +259 −0 SharpPcap/WinPcap/WinPcapDeviceList.cs
View
309 PacketDotNet/Ieee80211FrameControlField.cs
@@ -0,0 +1,309 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// See http://www.ucertify.com/article/ieee-802-11-frame-format.html
+ /// </summary>
+ public class Ieee80211FrameControlField
+ {
+ /// <summary>
+ /// Protocol version
+ /// </summary>
+ public byte ProtocolVersion
+ {
+ get
+ {
+ return (byte)(Field >> 14);
+ }
+ }
+
+ /// <summary>
+ /// Types of frames
+ /// </summary>
+ public enum FrameTypes
+ {
+ /// <summary>
+ /// Association request
+ /// </summary>
+ ManagementAssociationRequest = 0x00,
+
+ /// <summary>
+ /// Association response
+ /// </summary>
+ ManagementAssociationResponse = 0x01,
+
+ /// <summary>
+ /// Reassociation request
+ /// </summary>
+ ManagementReassociationRequest = 0x02,
+
+ /// <summary>
+ /// Reassociation response
+ /// </summary>
+ ManagementReassociationResponse = 0x03,
+
+ /// <summary>
+ /// Probe request
+ /// </summary>
+ ManagementProbeRequest = 0x04,
+
+ /// <summary>
+ /// Probe response
+ /// </summary>
+ ManagementProbeResponse = 0x5,
+
+ /// <summary>
+ /// Reserved 0
+ /// </summary>
+ ManagementReserved0 = 0x6,
+
+ /// <summary>
+ /// Reserved 1
+ /// </summary>
+ ManagementReserved1 = 0x7,
+
+ /// <summary>
+ /// Becon
+ /// </summary>
+ ManagementBecon = 0x8,
+
+ /// <summary>
+ /// ATIM
+ /// </summary>
+ ManagementATIM = 0x9,
+
+ /// <summary>
+ /// Disassociation
+ /// </summary>
+ ManagementDisassociation = 0xA,
+
+ /// <summary>
+ /// Authentication
+ /// </summary>
+ ManagementAuthentication = 0xB,
+
+ /// <summary>
+ /// Deauthentication
+ /// </summary>
+ ManagementDeauthentication = 0xC,
+
+ /// <summary>
+ /// Reserved 2
+ /// </summary>
+ ManagementReserved2 = 0xD,
+
+ /// <summary>
+ /// Reserved 3
+ /// </summary>
+ ManagementReserved3 = 0xE,
+
+ /// <summary>
+ /// PS poll
+ /// </summary>
+ ControlPSPoll = 0x1A,
+
+ /// <summary>
+ /// RTS
+ /// </summary>
+ ControlRTS = 0x1B,
+
+ /// <summary>
+ /// CTS
+ /// </summary>
+ ControlCTS = 0x1C,
+
+ /// <summary>
+ /// ACK
+ /// </summary>
+ ControlACK = 0x1D,
+
+ /// <summary>
+ /// CF-End
+ /// </summary>
+ ControlCFEnd = 0x1E,
+ /// <summary>
+ /// CF-End CF-Ack
+ /// </summary>
+ ControlCFEndCFACK = 0x1F,
+
+ /// <summary>
+ /// Data
+ /// </summary>
+ Data = 0x20,
+
+ /// <summary>
+ /// CF-ACK
+ /// </summary>
+ DataCFACK = 0x21,
+
+ /// <summary>
+ /// CF-Poll
+ /// </summary>
+ DataCFPoll = 0x22,
+
+ /// <summary>
+ /// CF-Ack CF-Poll
+ /// </summary>
+ DataCFAckCFPoll = 0x23,
+
+ /// <summary>
+ /// Null function no data
+ /// </summary>
+ DataNullFunctionNoData = 0x24,
+
+ /// <summary>
+ /// CF-Ack No data
+ /// </summary>
+ DataCFAckNoData = 0x25,
+
+ /// <summary>
+ /// CF-Poll no data
+ /// </summary>
+ DataCFPollNoData = 0x26,
+
+ /// <summary>
+ /// CF-Ack CF-Poll no data
+ /// </summary>
+ DataCFAckCFPollNoData = 0x27
+ };
+
+ /// <summary>
+ /// Helps to identify the type of WLAN frame, control data and management are
+ /// the various frame types defined in IEEE 802.11
+ /// </summary>
+ public FrameTypes Types
+ {
+ get
+ {
+ return (FrameTypes)((Field >> 8) & 0x3F);
+ }
+ }
+
+ /// <summary>
+ /// Is set to 1 when the frame is sent to Distribution System (DS)
+ /// </summary>
+ public bool ToDS
+ {
+ get
+ {
+ return (((Field >> 7) & 0x1) == 1) ? true : false;
+ }
+ }
+
+ /// <summary>
+ /// Is set to 1 when the frame is received from the Distribution System (DS)
+ /// </summary>
+ public bool FromDS
+ {
+ get
+ {
+ return (((Field >> 6) & 0x1) == 1) ? true : false;
+ }
+ }
+
+ /// <summary>
+ /// More Fragment is set to 1 when there are more fragments belonging to the same
+ /// frame following the current fragment
+ /// </summary>
+ public bool MoreFragments
+ {
+ get
+ {
+ return (((Field >> 5) & 0x1) == 1) ? true : false;
+ }
+ }
+
+ /// <summary>
+ /// Indicates that this fragment is a retransmission of a previously transmitted fragment.
+ /// (For receiver to recognize duplicate transmissions of frames)
+ /// </summary>
+ public bool Retry
+ {
+ get
+ {
+ return (((Field >> 4) & 0x1) == 1) ? true : false;
+ }
+ }
+
+ /// <summary>
+ /// Indicates the power management mode that the station will be in after the transmission of the frame
+ /// </summary>
+ public bool PowerManagement
+ {
+ get
+ {
+ return (((Field >> 3) & 0x1) == 1) ? true : false;
+ }
+ }
+
+ /// <summary>
+ /// Indicates that there are more frames buffered for this station
+ /// </summary>
+ public bool MoreData
+ {
+ get
+ {
+ return (((Field >> 2) & 0x1) == 1) ? true : false;
+ }
+ }
+
+ /// <summary>
+ /// Indicates that the frame body is encrypted according to the WEP (wired equivalent privacy) algorithm
+ /// </summary>
+ public bool Wep
+ {
+ get
+ {
+ return (((Field >> 1) & 0x1) == 1) ? true : false;
+ }
+ }
+
+ /// <summary>
+ /// Bit is set when the "strict ordering" delivery method is employed. Frames and
+ /// fragments are not always sent in order as it causes a transmission performance penalty.
+ /// </summary>
+ public bool Order
+ {
+ get
+ {
+ return ((Field & 0x1) == 1) ? true : false;
+ }
+ }
+
+ private UInt16 Field;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="field">
+ /// A <see cref="UInt16"/>
+ /// </param>
+ public Ieee80211FrameControlField(UInt16 field)
+ {
+ this.Field = field;
+ }
+ }
+}
View
50 PacketDotNet/Ieee80211MacFields.cs
@@ -0,0 +1,50 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+using System;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// See http://www.ucertify.com/article/ieee-802-11-frame-format.html
+ ///
+ /// NOTE: All positions are not defined here because the frame type changes
+ /// whether some address fields are present or not, causing the sequence control
+ /// field to move. In addition the payload size determines where the frame control
+ /// sequence value is as it is after the payload bytes, if any payload is present
+ /// </summary>
+ class Ieee80211MacFields
+ {
+ public readonly static int FrameControlLength = 2;
+ public readonly static int DurationIDLength = 2;
+ public readonly static int AddressLength = EthernetFields.MacAddressLength;
+ public readonly static int SequenceControlLength = 4;
+ public readonly static int FrameCheckSequenceLength = 4;
+
+ public readonly static int FrameControlPosition = 0;
+ public readonly static int DurationIDPosition;
+ public readonly static int Address1Position;
+
+ static Ieee80211MacFields()
+ {
+ DurationIDPosition = FrameControlPosition + FrameControlLength;
+ Address1Position = DurationIDPosition + DurationIDLength;
+ }
+ }
+}
View
362 PacketDotNet/Ieee80211MacFrame.cs
@@ -0,0 +1,362 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+using System;
+using System.Net.NetworkInformation;
+using PacketDotNet.Utils;
+using MiscUtil.Conversion;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// Packet class has common fields, FrameControl and Duration and
+ /// a specific object class that is set based on the type of
+ /// the frame
+ ///
+ /// See http://www.ucertify.com/article/ieee-802-11-frame-format.html
+ /// </summary>
+ public class Ieee80211MacFrame : Packet
+ {
+#if DEBUG
+ private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+#else
+ // NOTE: No need to warn about lack of use, the compiler won't
+ // put any calls to 'log' here but we need 'log' to exist to compile
+#pragma warning disable 0169, 0649
+ private static readonly ILogInactive log;
+#pragma warning restore 0169, 0649
+#endif
+
+ private int GetOffsetForAddress(int addressIndex)
+ {
+ int offset = header.Offset;
+
+ offset += Ieee80211MacFields.Address1Position + Ieee80211MacFields.AddressLength * addressIndex;
+
+ // the 4th address is AFTER the sequence control field so we need to skip past that
+ // field
+ if (addressIndex == 4)
+ offset += Ieee80211MacFields.SequenceControlLength;
+
+ return offset;
+ }
+
+ /// <summary>
+ /// Frame control bytes are the first two bytes of the frame
+ /// </summary>
+ public UInt16 FrameControlBytes
+ {
+ get
+ {
+ return EndianBitConverter.Big.ToUInt16(header.Bytes,
+ header.Offset);
+ }
+
+ set
+ {
+ EndianBitConverter.Big.CopyBytes(value,
+ header.Bytes,
+ header.Offset);
+ }
+ }
+
+ /// <summary>
+ /// Frame control field
+ /// </summary>
+ public Ieee80211FrameControlField FrameControl
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="addressIndex">Zero based address to look up</param>
+ /// <param name="address"></param>
+ private void SetAddress(int addressIndex, PhysicalAddress address)
+ {
+ var offset = GetOffsetForAddress(addressIndex);
+
+ // using the offset, set the address
+ byte[] hwAddress = address.GetAddressBytes();
+ if (hwAddress.Length != Ieee80211MacFields.AddressLength)
+ {
+ throw new System.InvalidOperationException("address length " + hwAddress.Length
+ + " not equal to the expected length of "
+ + Ieee80211MacFields.AddressLength);
+ }
+
+ Array.Copy(hwAddress, 0, header.Bytes, offset,
+ hwAddress.Length);
+ }
+
+ private PhysicalAddress GetAddress(int addressIndex)
+ {
+ var offset = GetOffsetForAddress(addressIndex);
+
+ byte[] hwAddress = new byte[Ieee80211MacFields.AddressLength];
+ Array.Copy(header.Bytes, offset,
+ hwAddress, 0, hwAddress.Length);
+ return new PhysicalAddress(hwAddress);
+ }
+
+ /// <summary>
+ /// Frame check sequence, the last thing in the 802.11 mac packet
+ /// </summary>
+ public UInt32 FrameCheckSequence
+ {
+ get
+ {
+ var offsetToEndOfData = payloadPacketOrData.TheByteArraySegment.Offset + payloadPacketOrData.TheByteArraySegment.Length;
+ return EndianBitConverter.Big.ToUInt32(header.Bytes,
+ offsetToEndOfData);
+ }
+
+ set
+ {
+ var offsetToEndOfData = payloadPacketOrData.TheByteArraySegment.Offset + payloadPacketOrData.TheByteArraySegment.Length;
+ EndianBitConverter.Big.CopyBytes(value,
+ header.Bytes,
+ offsetToEndOfData);
+ }
+ }
+
+ /// <summary>
+ /// Interfaces for all inner frames
+ /// </summary>
+ public interface InnerFramePacket
+ {
+ /// <summary>
+ /// Length of the frame
+ /// </summary>
+ int FrameSize { get; }
+ }
+
+ /// <summary>
+ /// RTS Frame has a ReceiverAddress[6], TransmitterAddress[6] and a FrameCheckSequence[4],
+ /// these fields follow the common FrameControl[2] and DurationId[2] fields
+ /// </summary>
+ public class RTSFrame : Packet, InnerFramePacket
+ {
+ /// <summary>
+ /// ReceiverAddress
+ /// </summary>
+ public PhysicalAddress ReceiverAddress
+ {
+ get
+ {
+ return parent.GetAddress(0);
+ }
+
+ set
+ {
+ parent.SetAddress(0, value);
+ }
+ }
+
+ /// <summary>
+ /// TransmitterAddress
+ /// </summary>
+ public PhysicalAddress TransmitterAddress
+ {
+ get
+ {
+ return parent.GetAddress(1);
+ }
+
+ set
+ {
+ parent.SetAddress(1, value);
+ }
+ }
+
+ /// <summary>
+ /// Length of the frame
+ /// </summary>
+ public int FrameSize
+ {
+ get
+ {
+ return Ieee80211MacFields.AddressLength * 2;
+ }
+ }
+
+ private Ieee80211MacFrame parent;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="parent">
+ /// A <see cref="Ieee80211MacFrame"/>
+ /// </param>
+ /// <param name="bas">
+ /// A <see cref="ByteArraySegment"/>
+ /// </param>
+ public RTSFrame(Ieee80211MacFrame parent, ByteArraySegment bas)
+ {
+ this.parent = parent;
+ header = new ByteArraySegment(bas);
+ header.Length = FrameSize;
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("[RTSFrame RA {0}, TA {1}]",
+ ReceiverAddress.ToString(),
+ TransmitterAddress.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Format of a CTS or an ACK frame
+ /// </summary>
+ public class CTSOrACKFrame : Packet, InnerFramePacket
+ {
+ /// <summary>
+ /// Receiver address
+ /// </summary>
+ public PhysicalAddress ReceiverAddress
+ {
+ get
+ {
+ return parent.GetAddress(0);
+ }
+
+ set
+ {
+ parent.SetAddress(0, value);
+ }
+ }
+
+ /// <summary>
+ /// Length of the frame
+ /// </summary>
+ public int FrameSize
+ {
+ get
+ {
+ return Ieee80211MacFields.AddressLength;
+ }
+ }
+
+ private Ieee80211MacFrame parent;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="parent">
+ /// A <see cref="Ieee80211MacFrame"/>
+ /// </param>
+ /// <param name="bas">
+ /// A <see cref="ByteArraySegment"/>
+ /// </param>
+ public CTSOrACKFrame(Ieee80211MacFrame parent, ByteArraySegment bas)
+ {
+ this.parent = parent;
+ header = new ByteArraySegment(bas);
+ header.Length = FrameSize;
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("[CTSOrACKFrame RA {0}]",
+ ReceiverAddress.ToString());
+ }
+ }
+
+ /// <summary>
+ /// One of RTS, CTS etc frames
+ /// </summary>
+ public InnerFramePacket InnerFrame
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="bas">
+ /// A <see cref="ByteArraySegment"/>
+ /// </param>
+ public Ieee80211MacFrame(ByteArraySegment bas)
+ {
+ log.Debug("");
+
+ // slice off the header portion as our header
+ header = new ByteArraySegment(bas);
+ const int defaultLength = 4;
+ header.Length = defaultLength;
+
+ FrameControl = new Ieee80211FrameControlField(FrameControlBytes);
+
+ // determine what kind of frame this is based on the type
+ if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlRTS)
+ {
+ InnerFrame = new RTSFrame(this, bas);
+ }
+ else if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlCTS)
+ {
+ InnerFrame = new CTSOrACKFrame(this, bas);
+ }
+ else if (FrameControl.Types == Ieee80211FrameControlField.FrameTypes.ControlACK)
+ {
+ InnerFrame = new CTSOrACKFrame(this, bas);
+ }
+ else
+ {
+ throw new System.NotImplementedException("FrameControl.Types of " + FrameControl.Types + " not handled");
+ }
+
+ header.Length = InnerFrame.FrameSize;
+
+ // store the payload, less the frame check sequence at the end
+ payloadPacketOrData = new PacketOrByteArraySegment();
+ payloadPacketOrData.TheByteArraySegment = header.EncapsulatedBytes();
+ payloadPacketOrData.TheByteArraySegment.Length -= Ieee80211MacFields.FrameCheckSequenceLength;
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("FrameControl {0}, InnerFrame {1}, FrameCheckSequence {2}",
+ FrameControl.ToString(),
+ InnerFrame.ToString(),
+ FrameCheckSequence);
+ }
+ }
+}
View
70 PacketDotNet/Ieee80211RadioFields.cs
@@ -0,0 +1,70 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+using System;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// As defined by Airpcap.h
+ ///
+ /// NOTE: PresentPosition may not be the only position present
+ /// as this the field can be extended if the high bit is set
+ /// </summary>
+ public class Ieee80211RadioFields
+ {
+ /// <summary>Length of the version field</summary>
+ public readonly static int VersionLength = 1;
+
+ /// <summary>Length of the pad field</summary>
+ public readonly static int PadLength = 1;
+
+ /// <summary>Length of the length field</summary>
+ public readonly static int LengthLength = 2;
+
+ /// <summary>Length of the first present field (others may follow)</summary>
+ public readonly static int PresentLength = 4;
+
+ /// <summary>Position of the version field</summary>
+ public readonly static int VersionPosition = 0;
+
+ /// <summary>Position of the padding field</summary>
+ public readonly static int PadPosition;
+
+ /// <summary>Position of the length field</summary>
+ public readonly static int LengthPosition;
+
+ /// <summary>Position of the first present field</summary>
+ public readonly static int PresentPosition;
+
+ /// <summary>Default header length, assuming one present field entry</summary>
+ public readonly static int DefaultHeaderLength;
+
+ static Ieee80211RadioFields()
+ {
+ PadPosition = VersionPosition + VersionLength;
+ LengthPosition = PadPosition + PadLength;
+ PresentPosition = LengthPosition + LengthLength;
+
+ // default to the normal header size until the header length can be read
+ DefaultHeaderLength = PresentPosition + PresentLength;
+ }
+ }
+};
+
View
233 PacketDotNet/Ieee80211RadioPacket.cs
@@ -0,0 +1,233 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.IO;
+using System.Text;
+using PacketDotNet.Utils;
+using MiscUtil.Conversion;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// .Net analog of a ieee80211_radiotap_header from airpcap.h
+ /// </summary>
+ public class Ieee80211RadioPacket : InternetLinkLayerPacket
+ {
+#if DEBUG
+ private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
+#else
+ // NOTE: No need to warn about lack of use, the compiler won't
+ // put any calls to 'log' here but we need 'log' to exist to compile
+#pragma warning disable 0169, 0649
+ private static readonly ILogInactive log;
+#pragma warning restore 0169, 0649
+#endif
+
+ /// <summary>
+ /// Version 0. Only increases for drastic changes, introduction of compatible
+ /// new fields does not count.
+ /// </summary>
+ public byte Version
+ {
+ get
+ {
+ return header.Bytes[header.Offset + Ieee80211RadioFields.VersionPosition];
+ }
+
+ internal set
+ {
+ header.Bytes[header.Offset + Ieee80211RadioFields.VersionPosition] = value;
+ }
+ }
+
+ /// <summary>
+ /// Length of the whole header in bytes, including it_version, it_pad, it_len
+ /// and data fields
+ /// </summary>
+ public UInt16 Length
+ {
+ get
+ {
+ return EndianBitConverter.Little.ToUInt16(header.Bytes,
+ header.Offset + Ieee80211RadioFields.LengthPosition);
+ }
+
+ set
+ {
+ EndianBitConverter.Little.CopyBytes(value,
+ header.Bytes,
+ header.Offset + Ieee80211RadioFields.LengthPosition);
+ }
+ }
+
+ /// <summary>
+ /// Returns an array of UInt32 bitmap entries. Each bit in the bitmap indicates
+ /// which fields are present. Set bit 31 (0x8000000)
+ /// to extend the bitmap by another 32 bits. Additional extensions are made
+ /// by setting bit 31.
+ /// </summary>
+ public UInt32[] Present
+ {
+ get
+ {
+ // make an array of the bitmask fields
+ // the highest bit indicates whether other bitmask fields follow
+ // the current field
+ var bitmaskFields = new List<UInt32>();
+ UInt32 bitmask = EndianBitConverter.Little.ToUInt32(header.Bytes,
+ header.Offset + Ieee80211RadioFields.PresentPosition);
+ bitmaskFields.Add(bitmask);
+ int bitmaskOffsetInBytes = 4;
+ while ((bitmask & (1 << 31)) == 1)
+ {
+ // retrieve the next field
+ bitmask = EndianBitConverter.Little.ToUInt32(header.Bytes,
+ header.Offset + Ieee80211RadioFields.PresentPosition + bitmaskOffsetInBytes);
+ bitmaskFields.Add(bitmask);
+ bitmaskOffsetInBytes += 4;
+ }
+
+ return bitmaskFields.ToArray();
+ }
+ }
+
+ internal Ieee80211RadioPacket(ByteArraySegment bas)
+ {
+ log.Debug("");
+
+ // slice off the header portion
+ header = new ByteArraySegment(bas);
+ header.Length = Ieee80211RadioFields.DefaultHeaderLength;
+
+ // update the header size based on the headers packet length
+ header.Length = Length;
+
+ // parse the encapsulated bytes
+// payloadPacketOrData = ParseEncapsulatedBytes(header, Type, Timeval);
+ }
+
+ /// <summary cref="Packet.ToString(StringOutputType)" />
+ public override string ToString(StringOutputType outputFormat)
+ {
+ var buffer = new StringBuilder();
+ string color = "";
+ string colorEscape = "";
+
+ if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
+ {
+ color = Color;
+ colorEscape = AnsiEscapeSequences.Reset;
+ }
+
+ if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
+ {
+ // build the output string
+ buffer.AppendFormat("{0}[Ieee80211RadioPacket: Version={2}, Length={3}, Present[0]=0x{4:x}]{1}",
+ color,
+ colorEscape,
+ Version,
+ Length,
+ Present[0]);
+ }
+
+ if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
+ {
+ // collect the properties and their value
+ Dictionary<string, string> properties = new Dictionary<string, string>();
+ properties.Add("version", Version.ToString());
+ properties.Add("length", Length.ToString());
+ properties.Add("present", " (0x" + Present[0].ToString("x") + ")");
+
+ var radioTapFields = this.RadioTapFields;
+
+ foreach (var r in radioTapFields)
+ {
+ properties.Add(r.FieldType.ToString(),
+ r.ToString());
+ }
+
+ // calculate the padding needed to right-justify the property names
+ int padLength = Utils.RandomUtils.LongestStringLength(new List<string>(properties.Keys));
+
+ // build the output string
+ buffer.AppendLine("Ieee80211RadioPacket");
+ foreach (var property in properties)
+ {
+ buffer.AppendLine("TAP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
+ }
+ buffer.AppendLine("TAP:");
+ }
+
+ // append the base output
+ buffer.Append(base.ToString(outputFormat));
+
+ return buffer.ToString();
+ }
+
+ /// <summary>
+ /// Array of radio tap fields
+ /// </summary>
+ public List<RadioTapField> RadioTapFields
+ {
+ get
+ {
+ var bitmasks = Present;
+
+ var retval = new List<RadioTapField>();
+
+ int bitIndex = 0;
+
+ // create a binary reader that points to the memory immediately after the bitmasks
+ var offset = header.Offset +
+ Ieee80211RadioFields.PresentPosition +
+ (bitmasks.Length) * Marshal.SizeOf(typeof(UInt32));
+ var br = new BinaryReader(new MemoryStream(header.Bytes,
+ offset,
+ (int)(Length - offset)));
+
+ // now go through each of the bitmask fields looking at the least significant
+ // bit first to retrieve each field
+ foreach (var bmask in bitmasks)
+ {
+ int[] bmaskArray = new int[1];
+ bmaskArray[0] = (int)bmask;
+ var ba = new BitArray(bmaskArray);
+
+ // look at all of the bits, note we don't want to consider the
+ // highest bit since that indicates another bitfield that follows
+ for (int x = 0; x < 31; x++)
+ {
+ if (ba[x] == true)
+ {
+ retval.Add(RadioTapField.Parse(bitIndex, br));
+ }
+ bitIndex++;
+ }
+ }
+
+ return retval;
+ }
+ }
+ }
+}
View
50 PacketDotNet/Ieee80211RadioTapChannelFlags.cs
@@ -0,0 +1,50 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+
+using System;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// Channel flags
+ /// </summary>
+ [Flags]
+ public enum Ieee80211RadioTapChannelFlags
+ {
+ /// <summary>Turbo channel</summary>
+ IEEE80211_CHAN_TURBO = 0x0010,
+ ///<summary>CCK channel</summary>
+ IEEE80211_CHAN_CCK = 0x0020,
+ /// <summary>OFDM channel</summary>
+ IEEE80211_CHAN_OFDM = 0x0040,
+ /// <summary>2 GHz spectrum channel</summary>
+ IEEE80211_CHAN_2GHZ = 0x0080,
+ /// <summary>5 GHz spectrum channel</summary>
+ IEEE80211_CHAN_5GHZ = 0x0100,
+ /// <summary>Only passive scan allowed</summary>
+ IEEE80211_CHAN_PASSIVE = 0x0200,
+ /// <summary>Dynamic CCK-OFDM channel</summary>
+ IEEE80211_CHAN_DYN = 0x0400,
+ /// <summary>GFSK channel (FHSS PHY)</summary>
+ IEEE80211_CHAN_GFSK = 0x0800,
+ /// <summary>11a static turbo channel only</summary>
+ IEEE80211_CHAN_STURBO = 0x2000
+ };
+}
View
704 PacketDotNet/Ieee80211RadioTapFields.cs
@@ -0,0 +1,704 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// Channel field
+ /// </summary>
+ public class ChannelRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_CHANNEL; } }
+
+ /// <summary>
+ /// Frequency in MHz
+ /// </summary>
+ public UInt16 FrequencyMHz { get; set; }
+
+ /// <summary>
+ /// Channel number derived from frequency
+ /// </summary>
+ public int Channel { get; set; }
+
+ /// <summary>
+ /// Channel flags
+ /// </summary>
+ public Ieee80211RadioTapChannelFlags Flags;
+
+ /// <summary>
+ /// Convert a frequency to a channel
+ /// </summary>
+ /// <param name="frequencyMHz">
+ /// A <see cref="System.Int32"/>
+ /// </param>
+ /// <returns>
+ /// A <see cref="System.Int32"/>
+ /// </returns>
+ public static int ChannelFromFrequencyMHz(int frequencyMHz)
+ {
+ switch (frequencyMHz)
+ {
+ case 2412:
+ return 1;
+ case 2417:
+ return 2;
+ case 2422:
+ return 3;
+ case 2427:
+ return 4;
+ case 2432:
+ return 5;
+ case 2437:
+ return 6;
+ case 2442:
+ return 7;
+ case 2447:
+ return 8;
+ case 2452:
+ return 9;
+ case 2457:
+ return 10;
+ case 2462:
+ return 11;
+ case 2467:
+ return 12;
+ case 2472:
+ return 13;
+ case 2484:
+ return 14;
+ default:
+ throw new System.NotImplementedException("Unknown frequencyMHz " + frequencyMHz);
+ };
+ }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public ChannelRadioTapField(BinaryReader br)
+ {
+ FrequencyMHz = br.ReadUInt16();
+ Channel = ChannelFromFrequencyMHz(FrequencyMHz);
+ Flags = (Ieee80211RadioTapChannelFlags)br.ReadUInt16();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("FrequencyMHz {0}, Channel {1}, Flags {2}",
+ FrequencyMHz, Channel, Flags);
+ }
+ }
+
+ /// <summary>
+ /// Fhss radio tap field
+ /// </summary>
+ public class FhssRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_FHSS; } }
+
+ /// <summary>
+ /// Hop set
+ /// </summary>
+ public byte ChannelHoppingSet { get; set; }
+
+ /// <summary>
+ /// Hop pattern
+ /// </summary>
+ public byte Pattern { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public FhssRadioTapField(BinaryReader br)
+ {
+ var u16 = br.ReadUInt16();
+
+ ChannelHoppingSet = (byte)(u16 & 0xff);
+ Pattern = (byte)((u16 >> 8) & 0xff);
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("ChannelHoppingSet {0}, Pattern {1}",
+ ChannelHoppingSet, Pattern);
+ }
+ }
+
+ /// <summary>
+ /// Radio tap flags
+ /// </summary>
+ public class FlagsRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_FLAGS; } }
+
+ /// <summary>
+ /// Flags set
+ /// </summary>
+ public Ieee80211RadioTapFlags Flags;
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public FlagsRadioTapField(BinaryReader br)
+ {
+ var u8 = br.ReadByte();
+ Flags = (Ieee80211RadioTapFlags)u8;
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("Flags {0}", Flags);
+ }
+ }
+
+ /// <summary>
+ /// Rate field
+ /// </summary>
+ public class RateRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_RATE; } }
+
+ /// <summary>
+ /// Rate in Mbps
+ /// </summary>
+ public double RateMbps { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public RateRadioTapField(BinaryReader br)
+ {
+ var u8 = br.ReadByte();
+ RateMbps = (0.5 * (u8 & 0x7f));
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("RateMbps {0}", RateMbps);
+ }
+ }
+
+ /// <summary>
+ /// Db antenna signal
+ /// </summary>
+ public class DbAntennaSignalRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_DB_ANTSIGNAL; } }
+
+ /// <summary>
+ /// Signal strength in dB
+ /// </summary>
+ public byte SignalStrengthdB { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public DbAntennaSignalRadioTapField(BinaryReader br)
+ {
+ SignalStrengthdB = br.ReadByte();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("SignalStrengthdB {0}", SignalStrengthdB);
+ }
+ }
+
+ /// <summary>
+ /// Antenna noise in dB
+ /// </summary>
+ public class DbAntennaNoiseRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_DB_ANTNOISE; } }
+
+ /// <summary>
+ /// Antenna noise in dB
+ /// </summary>
+ public byte AntennaNoisedB { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public DbAntennaNoiseRadioTapField(BinaryReader br)
+ {
+ AntennaNoisedB = br.ReadByte();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("AntennaNoisedB {0}", AntennaNoisedB);
+ }
+ }
+
+ /// <summary>
+ /// Antenna field
+ /// </summary>
+ public class AntennaRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_ANTENNA; } }
+
+ /// <summary>
+ /// Antenna number
+ /// </summary>
+ public byte Antenna { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public AntennaRadioTapField(BinaryReader br)
+ {
+ Antenna = br.ReadByte();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("Antenna {0}", Antenna);
+ }
+ }
+
+ /// <summary>
+ /// Antenna signal in dBm
+ /// </summary>
+ public class DbmAntennaSignalRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_DBM_ANTSIGNAL; } }
+
+ /// <summary>
+ /// Antenna signal in dBm
+ /// </summary>
+ public sbyte AntennaSignalDbm { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public DbmAntennaSignalRadioTapField(BinaryReader br)
+ {
+ AntennaSignalDbm = br.ReadSByte();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("AntennaSignalDbm {0}", AntennaSignalDbm);
+ }
+ }
+
+ /// <summary>
+ /// Antenna noise in dBm
+ /// </summary>
+ public class DbmAntennaNoiseRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_DBM_ANTNOISE; } }
+
+ /// <summary>
+ /// Antenna noise in dBm
+ /// </summary>
+ public sbyte AntennaNoisedBm { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public DbmAntennaNoiseRadioTapField(BinaryReader br)
+ {
+ AntennaNoisedBm = br.ReadSByte();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("AntennaNoisedBm {0}", AntennaNoisedBm);
+ }
+ }
+
+ /// <summary>
+ /// Lock quality
+ /// </summary>
+ public class LockQualityRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_LOCK_QUALITY; } }
+
+ /// <summary>
+ /// Signal quality
+ /// </summary>
+ public UInt16 SignalQuality { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public LockQualityRadioTapField(BinaryReader br)
+ {
+ SignalQuality = br.ReadUInt16();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("SignalQuality {0}", SignalQuality);
+ }
+ }
+
+ /// <summary>
+ /// Tsft radio tap field
+ /// </summary>
+ public class TsftRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_TSFT; } }
+
+ /// <summary>
+ /// Timestamp in microseconds
+ /// </summary>
+ public UInt64 TimestampUsec { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public TsftRadioTapField(BinaryReader br)
+ {
+ TimestampUsec = br.ReadUInt64();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("TimestampUsec {0}", TimestampUsec);
+ }
+ }
+
+ /// <summary>
+ /// Fcs field
+ /// </summary>
+ public class FcsRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_FCS; } }
+
+ /// <summary>
+ /// Frame check sequence
+ /// </summary>
+ public UInt32 FrameCheckSequence { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public FcsRadioTapField(BinaryReader br)
+ {
+ FrameCheckSequence = (UInt32)System.Net.IPAddress.HostToNetworkOrder(br.ReadInt32());
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("FrameCheckSequence {0}", FrameCheckSequence);
+ }
+ }
+
+ /// <summary>
+ /// Transmit power expressed as unitless distance from max
+ /// power set at factory calibration. 0 is max power.
+ /// Monotonically nondecreasing with lower power levels.
+ /// </summary>
+ public class TxAttenuationRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_DB_TX_ATTENUATION; } }
+
+ /// <summary>
+ /// Transmit power
+ /// </summary>
+ public int TxPower { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public TxAttenuationRadioTapField(BinaryReader br)
+ {
+ TxPower = -(int)br.ReadUInt16();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("TxPower {0}", TxPower);
+ }
+ }
+
+ /// <summary>
+ /// Transmit power expressed as decibel distance from max power
+ /// set at factory calibration. 0 is max power. Monotonically
+ /// nondecreasing with lower power levels.
+ /// </summary>
+ public class DbTxAttenuationRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_DB_TX_ATTENUATION; } }
+
+ /// <summary>
+ /// Transmit power
+ /// </summary>
+ public int TxPowerdB { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public DbTxAttenuationRadioTapField(BinaryReader br)
+ {
+ TxPowerdB = -(int)br.ReadByte();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("TxPowerdB {0}", TxPowerdB);
+ }
+ }
+
+ /// <summary>
+ /// Transmit power expressed as dBm (decibels from a 1 milliwatt
+ /// reference). This is the absolute power level measured at
+ /// the antenna port.
+ /// </summary>
+ public class DbmTxPowerRadioTapField : RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public override Ieee80211RadioTapType FieldType { get { return Ieee80211RadioTapType.IEEE80211_RADIOTAP_DBM_TX_POWER; } }
+
+ /// <summary>
+ /// Tx power in dBm
+ /// </summary>
+ public sbyte TxPowerdBm { get; set; }
+
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ public DbmTxPowerRadioTapField(BinaryReader br)
+ {
+ TxPowerdBm = br.ReadSByte();
+ }
+
+ /// <summary>
+ /// ToString() override
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return string.Format("TxPowerdBm {0}", TxPowerdBm);
+ }
+ }
+
+ /// <summary>
+ /// Abstract class for all radio tap fields
+ /// </summary>
+ public abstract class RadioTapField
+ {
+ /// <summary>Type of the field</summary>
+ public abstract Ieee80211RadioTapType FieldType
+ { get; }
+
+ /// <summary>
+ /// Parse a radio tap field, indicated by bitIndex, from a given BinaryReader
+ /// </summary>
+ /// <param name="bitIndex">
+ /// A <see cref="System.Int32"/>
+ /// </param>
+ /// <param name="br">
+ /// A <see cref="BinaryReader"/>
+ /// </param>
+ /// <returns>
+ /// A <see cref="RadioTapField"/>
+ /// </returns>
+ public static RadioTapField Parse(int bitIndex, BinaryReader br)
+ {
+ var Type = (Ieee80211RadioTapType)bitIndex;
+ switch (Type)
+ {
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_FLAGS:
+ return new FlagsRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_RATE:
+ return new RateRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_DB_ANTSIGNAL:
+ return new DbAntennaSignalRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_DB_ANTNOISE:
+ return new DbAntennaNoiseRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_ANTENNA:
+ return new AntennaRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
+ return new DbmAntennaSignalRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_DBM_ANTNOISE:
+ return new DbmAntennaNoiseRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_CHANNEL:
+ return new ChannelRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_FHSS:
+ return new FhssRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_LOCK_QUALITY:
+ return new LockQualityRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_TX_ATTENUATION:
+ return new TxAttenuationRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
+ return new DbTxAttenuationRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_DBM_TX_POWER:
+ return new DbmTxPowerRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_TSFT:
+ return new TsftRadioTapField(br);
+ case Ieee80211RadioTapType.IEEE80211_RADIOTAP_FCS:
+ return new FcsRadioTapField(br);
+ default:
+ throw new System.NotImplementedException("Unknown bitIndex of " + bitIndex);
+ }
+ }
+ };
+}
View
52 PacketDotNet/Ieee80211RadioTapFlags.cs
@@ -0,0 +1,52 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+
+using System;
+
+namespace PacketDotNet
+{
+ /// <summary>
+ /// Radio tap flags
+ /// </summary>
+ [Flags]
+ public enum Ieee80211RadioTapFlags
+ {
+ /// <summary>
+ /// sent/received during cfp
+ /// </summary>
+ CFP = 0x01,
+ /// <summary>
+ /// sent/received with short preamble
+ /// </summary>
+ ShortPreamble = 0x02,
+ /// <summary>
+ /// sent/received with WEP encryption
+ /// </summary>
+ WepEncrypted = 0x04,
+ /// <summary>
+ /// sent/received with fragmentation
+ /// </summary>
+ Fragmentation = 0x08,
+ /// <summary>
+ /// frame includes FCS
+ /// </summary>
+ FcsIncludedInFrame = 0x10
+ };
+}
View
176 PacketDotNet/Ieee80211RadioTapType.cs
@@ -0,0 +1,176 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Chris Morgan <chmorgan@gmail.com>
+ */
+
+using System;
+
+namespace PacketDotNet
+{
+ ///<summary>
+ /// NOTE: Might be out-of-date information since it mentions Ethereal
+ /// NOTE: ethereal does NOT handle the following:
+ /// IEEE80211_RADIOTAP_FHSS:
+ /// IEEE80211_RADIOTAP_LOCK_QUALITY:
+ /// IEEE80211_RADIOTAP_TX_ATTENUATION:
+ /// IEEE80211_RADIOTAP_DB_TX_ATTENUATION:
+ /// </summary>
+ [Flags]
+ public enum Ieee80211RadioTapType : int
+ {
+ /// <summary>
+ /// IEEE80211_RADIOTAP_TSFT u_int64_t microseconds
+ ///
+ /// Value in microseconds of the MAC's 64-bit 802.11 Time
+ /// Synchronization Function timer when the first bit of the
+ /// MPDU arrived at the MAC. For received frames, only.
+ ///
+ /// </summary>
+ IEEE80211_RADIOTAP_TSFT = 0,
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_FLAGS u_int8_t bitmap
+ ///
+ /// Properties of transmitted and received frames. See flags
+ /// defined below.
+ /// </summary>
+ IEEE80211_RADIOTAP_FLAGS = 1,
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_RATE u_int8_t 500kb/s
+ ///
+ /// Tx/Rx data rate
+ /// </summary>
+ IEEE80211_RADIOTAP_RATE = 2,
+
+ ///<summary>
+ /// IEEE80211_RADIOTAP_CHANNEL 2 x u_int16_t MHz, bitmap
+ ///
+ /// Tx/Rx frequency in MHz, followed by flags (see below).
+ ///</summary>
+ IEEE80211_RADIOTAP_CHANNEL = 3,
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_FHSS u_int16_t see below
+ ///
+ /// For frequency-hopping radios, the hop set (first byte)
+ /// and pattern (second byte).
+ /// </summary>
+ IEEE80211_RADIOTAP_FHSS = 4,
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from
+ /// one milliwatt (dBm)
+ ///
+ /// RF signal power at the antenna, decibel difference from
+ /// one milliwatt.
+ /// </summary>
+ IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from
+ /// one milliwatt (dBm)
+ ///
+ /// RF noise power at the antenna, decibel difference from one
+ /// milliwatt.
+ /// </summary>
+ IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_LOCK_QUALITY u_int16_t unitless
+ ///
+ /// Quality of Barker code lock. Unitless. Monotonically
+ /// nondecreasing with "better" lock strength. Called "Signal
+ /// Quality" in datasheets. (Is there a standard way to measure
+ /// this?)
+ /// </summary>
+ IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_TX_ATTENUATION u_int16_t unitless
+ ///
+ /// Transmit power expressed as unitless distance from max
+ /// power set at factory calibration. 0 is max power.
+ /// Monotonically nondecreasing with lower power levels.
+ /// </summary>
+ IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_DB_TX_ATTENUATION u_int16_t decibels (dB)
+ ///
+ /// Transmit power expressed as decibel distance from max power
+ /// set at factory calibration. 0 is max power. Monotonically
+ /// nondecreasing with lower power levels.
+ /// </summary>
+ IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from
+ /// one milliwatt (dBm)
+ ///
+ /// Transmit power expressed as dBm (decibels from a 1 milliwatt
+ /// reference). This is the absolute power level measured at
+ /// the antenna port.
+ /// </summary>
+ IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_ANTENNA u_int8_t antenna index
+ ///
+ /// Unitless indication of the Rx/Tx antenna for this packet.
+ /// The first antenna is antenna 0.
+ /// </summary>
+ IEEE80211_RADIOTAP_ANTENNA = 11,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_DB_ANTSIGNAL u_int8_t decibel (dB)
+ ///
+ /// RF signal power at the antenna, decibel difference from an
+ /// arbitrary, fixed reference.
+ /// </summary>
+ IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_DB_ANTNOISE u_int8_t decibel (dB)
+ ///
+ /// RF noise power at the antenna, decibel difference from an
+ /// arbitrary, fixed reference point.
+ /// </summary>
+ IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
+
+
+ /// <summary>
+ /// IEEE80211_RADIOTAP_FCS u_int32_t data
+ ///
+ /// FCS from frame in network byte order.
+ /// </summary>
+ IEEE80211_RADIOTAP_FCS = 14,
+
+ /// <summary>
+ /// Indicates that the flags bitmaps have been extended
+ /// </summary>
+ IEEE80211_RADIOTAP_EXT = 31,
+ };
+}
View
42 PacketDotNet/StringOutputType.cs
@@ -0,0 +1,42 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+using System;
+namespace PacketDotNet
+{
+ /// <summary>
+ /// The available types of strings that the ToString(StringOutputType) can handle.
+ /// </summary>
+ public enum StringOutputType
+ {
+ /// <summary>
+ /// Outputs the packet info on a single line
+ /// </summary>
+ Normal,
+ /// <summary>
+ /// Outputs the packet info on a single line with coloring
+ /// </summary>
+ Colored,
+ /// <summary>
+ /// Outputs the detailed packet info
+ /// </summary>
+ Verbose,
+ /// <summary>
+ /// Outputs the detailed packet info with coloring
+ /// </summary>
+ VerboseColored
+ }
+}
View
96 PacketDotNet/Tcp/AlternateChecksumData.cs
@@ -0,0 +1,96 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Evan Plaice <evanplaice@gmail.com>
+ */
+using System;
+using MiscUtil.Conversion;
+using PacketDotNet.Utils;
+
+namespace PacketDotNet.Tcp
+{
+ /// <summary>
+ /// Alternative Checksum Date
+ /// Used as an extension to Alternative Checksum Response when the
+ /// checksum is longer than the standard 16bit TCP Checksum field
+ /// </summary>
+ /// <remarks>
+ /// References:
+ /// http://datatracker.ietf.org/doc/rfc1146/
+ /// </remarks>
+ public class AlternateChecksumData : Option
+ {
+ #region Constructors
+
+ /// <summary>
+ /// Creates an Alternate Checksum Data Option
+ /// </summary>
+ /// <param name="bytes">
+ /// A <see cref="System.Byte[]"/>
+ /// </param>
+ /// <param name="offset">
+ /// A <see cref="System.Int32"/>
+ /// </param>
+ /// <param name="length">
+ /// A <see cref="System.Int32"/>
+ /// </param>
+ public AlternateChecksumData(byte[] bytes, int offset, int length) :
+ base(bytes, offset, length)
+ { }
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// The array of attached Checksum
+ /// </summary>
+ public byte[] Data
+ {
+ get
+ {
+ byte[] data = new byte[Length - DataFieldOffset];
+ Array.Copy(Bytes, DataFieldOffset, data, 0, data.Length);
+ return data;
+ }
+ }
+
+ #endregion
+
+ #region Methods
+
+ /// <summary>
+ /// Returns the Option info as a string
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return "[" + Kind.ToString() + ": Data=0x" + Data.ToString() + "]";
+ }
+
+ #endregion
+
+ #region Members
+
+ // the offset (in bytes) of the Data Field
+ const int DataFieldOffset = 2;
+
+ #endregion
+ }
+}
View
90 PacketDotNet/Tcp/AlternateChecksumRequest.cs
@@ -0,0 +1,90 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Evan Plaice <evanplaice@gmail.com>
+ */
+using System;
+using MiscUtil.Conversion;
+using PacketDotNet.Utils;
+
+namespace PacketDotNet.Tcp
+{
+ /// <summary>
+ /// AlternateChecksumRequest Option
+ /// </summary>
+ public class AlternateChecksumRequest : Option
+ {
+ #region Constructors
+
+ /// <summary>
+ /// Creates an Alternate Checksum Request Option
+ /// Used to negotiate an alternative checksum algorithm in a connection
+ /// </summary>
+ /// <param name="bytes">
+ /// A <see cref="System.Byte[]"/>
+ /// </param>
+ /// <param name="offset">
+ /// A <see cref="System.Int32"/>
+ /// </param>
+ /// <param name="length">
+ /// A <see cref="System.Int32"/>
+ /// </param>
+ /// <remarks>
+ /// References:
+ /// http://datatracker.ietf.org/doc/rfc1146/
+ /// </remarks>
+ public AlternateChecksumRequest(byte[] bytes, int offset, int length) :
+ base(bytes, offset, length)
+ { }
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// The Checksum
+ /// </summary>
+ public ChecksumAlgorighmType Checksum
+ {
+ get { return (ChecksumAlgorighmType)Bytes[ChecksumFieldOffset]; }
+ }
+
+ #endregion
+
+ #region Methods
+
+ /// <summary>
+ /// Returns the Option info as a string
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public override string ToString()
+ {
+ return "[" + Kind.ToString() + ": ChecksumType=" + Checksum.ToString() + "]";
+ }
+
+ #endregion
+
+ #region Members
+
+ // the offset (in bytes) of the Checksum field
+ const int ChecksumFieldOffset = 2;
+
+ #endregion
+ }
+}
View
47 PacketDotNet/Tcp/ChecksumAlgorighmType.cs
@@ -0,0 +1,47 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Evan Plaice <evanplaice@gmail.com>
+ */
+using System;
+
+namespace PacketDotNet.Tcp
+{
+ /// <summary>
+ /// Specifies the different types of algorithms that the
+ /// Alternative Checksum option are allowed to use
+ /// </summary>
+ /// <remarks>
+ /// References:
+ /// http://datatracker.ietf.org/doc/rfc1146/
+ /// </remarks>
+ public enum ChecksumAlgorighmType
+ {
+ /// <summary>Standard TCP Checksum Algorithm</summary>
+ TCPChecksum = 0,
+
+ /// <summary>8-bit Fletchers Algorighm</summary>
+ EightBitFletchersAlgorithm = 1,
+
+ /// <summary>16-bit Fletchers Algorithm</summary>
+ SixteenBitFletchersAlgorithm = 2,
+
+ /// <summary>Redundant Checksum Avoidance</summary>
+ RedundantChecksumAvoidance = 3
+ }
+}
+
View
53 PacketDotNet/Tcp/Echo.cs
@@ -0,0 +1,53 @@
+/*
+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 <http://www.gnu.org/licenses/>.
+*/
+/*
+ * Copyright 2010 Evan Plaice <evanplaice@gmail.com>
+ */
+using System;
+
+namespace PacketDotNet.Tcp
+{
+ /// <summary>
+ /// An Echo Option
+ /// throws an exception because Echo Options
+ /// are obsolete as per their spec
+ /// </summary>
+ public class Echo : Option
+ {
+ #region Constructors
+
+ /// <summary>
+ /// Creates an Echo Option
+ /// </summary>
+ /// <param name="bytes">
+ /// A <see cref="System.Byte[]"/>