Commit 0a4f4c5b authored by Brickner_cp's avatar Brickner_cp

Code Analysis and Documentation - 3 warnings left.

parent ff603078
...@@ -95,11 +95,11 @@ namespace PcapDotNet.Base ...@@ -95,11 +95,11 @@ namespace PcapDotNet.Base
} }
/// <summary> /// <summary>
/// Returns a hash code by xoring all the bytes. /// Returns a string by converting all the bytes to a hexadecimal string.
/// Each byte is xored with the next 8 bits of the integer.
/// </summary> /// </summary>
/// <param name="sequence">The bytes to xor.</param> /// <param name="sequence">The bytes to convert to a string.</param>
/// <returns>The hash code resulted by xoring all the bytes.</returns> /// <param name="separator">The string to put between every two bytes.</param>
/// <returns>The string resulted by converting all the bytes to hexadecimal strings and putting the separator between them.</returns>
public static string BytesSequenceToHexadecimalString(this IEnumerable<byte> sequence, string separator) public static string BytesSequenceToHexadecimalString(this IEnumerable<byte> sequence, string separator)
{ {
return sequence.Aggregate(string.Empty, return sequence.Aggregate(string.Empty,
......
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Words>
<Unrecognized>
<!--Word>cb</Word-->
</Unrecognized>
<Recognized>
<Word>pcap</Word>
</Recognized>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
</Deprecated>
<Compound>
<!--Term CompoundAlternate="DataStore">datastore</Term-->
</Compound>
<DiscreteExceptions>
<!--Term>netmask</Term-->
</DiscreteExceptions>
</Words>
<Acronyms>
<CasingExceptions>
<!-->Acronym>Ip</Acronym-->
</CasingExceptions>
</Acronyms>
</Dictionary>
\ No newline at end of file
...@@ -71,6 +71,9 @@ ...@@ -71,6 +71,9 @@
<ItemGroup> <ItemGroup>
<None Include="..\PcapDotNet.snk" /> <None Include="..\PcapDotNet.snk" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="CodeAnalysisDictionary.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
using System; using System;
using System.Collections.ObjectModel;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
namespace PcapDotNet.Packets.Arp namespace PcapDotNet.Packets.Arp
...@@ -9,7 +10,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -9,7 +10,7 @@ namespace PcapDotNet.Packets.Arp
/// Note that the EtherType (0x0806) is used in the Ethernet header, and should not be used as the PTYPE of the ARP packet. /// Note that the EtherType (0x0806) is used in the Ethernet header, and should not be used as the PTYPE of the ARP packet.
/// The ARP type (0x0806) should never be used in the PTYPE field of an ARP packet, since a hardware protocol address should never be linked to the ARP protocol. /// The ARP type (0x0806) should never be used in the PTYPE field of an ARP packet, since a hardware protocol address should never be linked to the ARP protocol.
/// Note that the packet structure shown in the table has SHA and THA as 48-bit fields and SPA and TPA as 32-bit fields but this is just for convenience /// Note that the packet structure shown in the table has SHA and THA as 48-bit fields and SPA and TPA as 32-bit fields but this is just for convenience
/// their actual lengths are determined by the hardware & protocol length fields. /// their actual lengths are determined by the hardware &amp; protocol length fields.
/// <pre> /// <pre>
/// +-----+------------------------+------------------------+-----------------------------------------------+ /// +-----+------------------------+------------------------+-----------------------------------------------+
/// | bit | 0-7 | 8-15 | 16-31 | /// | bit | 0-7 | 8-15 | 16-31 |
...@@ -42,8 +43,14 @@ namespace PcapDotNet.Packets.Arp ...@@ -42,8 +43,14 @@ namespace PcapDotNet.Packets.Arp
public const int SenderHardwareAddress = 8; public const int SenderHardwareAddress = 8;
} }
/// <summary>
/// The number of bytes in the ARP header without the addresses (that vary in size).
/// </summary>
public const int HeaderBaseLength = 8; public const int HeaderBaseLength = 8;
/// <summary>
/// The number of bytes in the ARP header.
/// </summary>
public int HeaderLength public int HeaderLength
{ {
get { return GetHeaderLength(HardwareLength, ProtocolLength); } get { return GetHeaderLength(HardwareLength, ProtocolLength); }
...@@ -92,36 +99,39 @@ namespace PcapDotNet.Packets.Arp ...@@ -92,36 +99,39 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// Hardware address of the sender. /// Hardware address of the sender.
/// </summary> /// </summary>
public byte[] SenderHardwareAddress public ReadOnlyCollection<byte> SenderHardwareAddress
{ {
get { return ReadBytes(Offset.SenderHardwareAddress, HardwareLength); } get { return new ReadOnlyCollection<byte>(ReadBytes(Offset.SenderHardwareAddress, HardwareLength)); }
} }
/// <summary> /// <summary>
/// Protocol address of the sender. /// Protocol address of the sender.
/// </summary> /// </summary>
public byte[] SenderProtocolAddress public ReadOnlyCollection<byte> SenderProtocolAddress
{ {
get { return ReadBytes(OffsetSenderProtocolAddress, ProtocolLength); } get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetSenderProtocolAddress, ProtocolLength)); }
} }
/// <summary> /// <summary>
/// Hardware address of the intended receiver. /// Hardware address of the intended receiver.
/// This field is ignored in requests. /// This field is ignored in requests.
/// </summary> /// </summary>
public byte[] TargetHardwareAddress public ReadOnlyCollection<byte> TargetHardwareAddress
{ {
get { return ReadBytes(OffsetTargetHardwareAddress, HardwareLength); } get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetTargetHardwareAddress, HardwareLength)); }
} }
/// <summary> /// <summary>
/// Protocol address of the intended receiver. /// Protocol address of the intended receiver.
/// </summary> /// </summary>
public byte[] TargetProtocolAddress public ReadOnlyCollection<byte> TargetProtocolAddress
{ {
get { return ReadBytes(OffsetTargetProtocolAddress, ProtocolLength); } get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetTargetProtocolAddress, ProtocolLength)); }
} }
/// <summary>
/// The default validity check always returns true.
/// </summary>
protected override bool CalculateIsValid() protected override bool CalculateIsValid()
{ {
return Length >= HeaderBaseLength && Length == HeaderLength; return Length >= HeaderBaseLength && Length == HeaderLength;
......
namespace PcapDotNet.Packets.Arp namespace PcapDotNet.Packets.Arp
{ {
/// <summary>
/// The data link layer protocol of the ARP protocol.
/// </summary>
public enum ArpHardwareType : ushort public enum ArpHardwareType : ushort
{ {
/// <summary>
/// Invalid hardware type
/// </summary>
None = 0,
/// <summary> /// <summary>
/// Ethernet (10Mb) /// Ethernet (10Mb)
/// </summary> /// </summary>
...@@ -35,17 +43,17 @@ namespace PcapDotNet.Packets.Arp ...@@ -35,17 +43,17 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// ARCNET /// ARCNET
/// </summary> /// </summary>
Arcnet = 7, AttachedResourceComputerNetwork = 7,
/// <summary> /// <summary>
/// Hyperchannel /// Hyperchannel
/// </summary> /// </summary>
Hyperchannel = 8, HyperChannel = 8,
/// <summary> /// <summary>
/// Lanstar /// Lanstar
/// </summary> /// </summary>
Lanstar = 9, LanStar = 9,
/// <summary> /// <summary>
/// Autonet Short Address /// Autonet Short Address
...@@ -70,7 +78,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -70,7 +78,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// SMDS /// SMDS
/// </summary> /// </summary>
Smds = 14, SwitchedMultimegabitDataService = 14,
/// <summary> /// <summary>
/// Frame Relay /// Frame Relay
...@@ -85,7 +93,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -85,7 +93,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// HDLC /// HDLC
/// </summary> /// </summary>
Hdlc = 17, HighLevelDataLinkControl = 17,
/// <summary> /// <summary>
/// Fibre Channel /// Fibre Channel
...@@ -110,7 +118,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -110,7 +118,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// MIL-STD-188-220 /// MIL-STD-188-220
/// </summary> /// </summary>
MilStd188_220 = 22, MilStd188Hyphen220 = 22,
/// <summary> /// <summary>
/// Metricom /// Metricom
...@@ -120,12 +128,12 @@ namespace PcapDotNet.Packets.Arp ...@@ -120,12 +128,12 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// IEEE 1394.1995 /// IEEE 1394.1995
/// </summary> /// </summary>
Ieee1394_1995 = 24, Ieee1394Dot1995 = 24,
/// <summary> /// <summary>
/// MAPOS /// MAPOS
/// </summary> /// </summary>
Mapos = 25, MultipleAccessOverSynchronousOpticalNetworkingOrSynchronousDigitalHierarchy = 25,
/// <summary> /// <summary>
/// Twinaxial /// Twinaxial
...@@ -135,7 +143,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -135,7 +143,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// EUI-64 /// EUI-64
/// </summary> /// </summary>
Eui64 = 27, ExtendedUniqueIdentifier64 = 27,
/// <summary> /// <summary>
/// HIPARP /// HIPARP
...@@ -145,7 +153,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -145,7 +153,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// IP and ARP over ISO 7816-3 /// IP and ARP over ISO 7816-3
/// </summary> /// </summary>
IpAndArpOverIso7816_3 = 29, IpAndArpOverIso7816Hyphen3 = 29,
/// <summary> /// <summary>
/// ARPSec /// ARPSec
......
namespace PcapDotNet.Packets.Arp namespace PcapDotNet.Packets.Arp
{ {
/// <summary>
/// Specifies the operation the ARP sender is performing.
/// </summary>
public enum ArpOperation : ushort public enum ArpOperation : ushort
{ {
/// <summary>
/// Invalid operation.
/// </summary>
None = 0,
/// <summary> /// <summary>
/// [RFC826][RFC5227] /// [RFC826][RFC5227]
/// </summary> /// </summary>
...@@ -68,7 +76,7 @@ namespace PcapDotNet.Packets.Arp ...@@ -68,7 +76,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary> /// <summary>
/// [RFC2176] /// [RFC2176]
/// </summary> /// </summary>
MultipleAccessOverSonetOrSdhUnarp = 23, MultipleAccessOverSynchronousOpticalNetworkingOrSynchronousDigitalHierarchyUnsolicitedArp = 23,
/// <summary> /// <summary>
/// [RFC5494] /// [RFC5494]
......
...@@ -38,6 +38,15 @@ ...@@ -38,6 +38,15 @@
<Word>genser</Word> <Word>genser</Word>
<Word>nsa</Word> <Word>nsa</Word>
<Word>md</Word> <Word>md</Word>
<Word>autonet</Word>
<Word>hiparp</Word>
<Word>infini</Word>
<Word>metricom</Word>
<Word>proteon</Word>
<Word>twinaxial</Word>
<Word>wiegand</Word>
<Word>arp</Word>
<Word>multimegabit</Word>
</Recognized> </Recognized>
<Deprecated> <Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term--> <!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
......
...@@ -152,6 +152,12 @@ namespace PcapDotNet.Packets ...@@ -152,6 +152,12 @@ namespace PcapDotNet.Packets
return true; return true;
} }
/// <summary>
/// Reads a requested number of bytes from a specific offset in the datagram.
/// </summary>
/// <param name="offset">The offset in the datagram to start reading.</param>
/// <param name="length">The number of bytes to read.</param>
/// <returns>The bytes read from the datagram starting from the given offset and in the given length.</returns>
protected byte[] ReadBytes(int offset, int length) protected byte[] ReadBytes(int offset, int length)
{ {
return Buffer.ReadBytes(StartOffset + offset, length); return Buffer.ReadBytes(StartOffset + offset, length);
......
...@@ -31,6 +31,9 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -31,6 +31,9 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary> /// </summary>
public const int HeaderLength = 14; public const int HeaderLength = 14;
/// <summary>
/// The broadcast MAC address (FF:FF:FF:FF:FF:FF).
/// </summary>
public static MacAddress BroadcastAddress public static MacAddress BroadcastAddress
{ {
get { return _broadcastAddress; } get { return _broadcastAddress; }
...@@ -98,6 +101,9 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -98,6 +101,9 @@ namespace PcapDotNet.Packets.Ethernet
} }
} }
/// <summary>
/// The Ethernet payload as an ARP datagram.
/// </summary>
public ArpDatagram Arp public ArpDatagram Arp
{ {
get get
......
...@@ -30,6 +30,21 @@ namespace PcapDotNet.Packets ...@@ -30,6 +30,21 @@ namespace PcapDotNet.Packets
return new Packet(buffer, timestamp, new DataLink(DataLinkKind.Ethernet)); return new Packet(buffer, timestamp, new DataLink(DataLinkKind.Ethernet));
} }
/// <summary>
/// Builds an ARP over Ethernet packet.
/// The ethernet destination will be ethernet broadcast.
/// </summary>
/// <param name="timestamp">The packet timestamp.</param>
/// <param name="ethernetSource">The Ethernet source mac address.</param>
/// <param name="arpProtocolType">Each protocol is assigned a number used in this field.</param>
/// <param name="arpOperation">Specifies the operation the sender is performing.</param>
/// <param name="arpSenderHardwareAddress">Hardware address of the sender.</param>
/// <param name="arpSenderProtocolAddress">Protocol address of the sender.</param>
/// <param name="arpTargetHardwareAddress">Hardware address of the intended receiver. This field is ignored in requests.</param>
/// <param name="arpTargetProtocolAddress">Protocol address of the intended receiver.</param>
/// <returns>A packet with an ARP over Ethernet datagram.</returns>
/// <exception cref="ArgumentException">The sender hardware or protocol addresses have different length.</exception>
public static Packet EthernetArp(DateTime timestamp, public static Packet EthernetArp(DateTime timestamp,
MacAddress ethernetSource, MacAddress ethernetSource,
EthernetType arpProtocolType, ArpOperation arpOperation, EthernetType arpProtocolType, ArpOperation arpOperation,
......
...@@ -230,6 +230,9 @@ namespace PcapDotNet.Packets.Transport ...@@ -230,6 +230,9 @@ namespace PcapDotNet.Packets.Transport
get { return (ControlBits & TcpControlBits.Fin) == TcpControlBits.Fin; } get { return (ControlBits & TcpControlBits.Fin) == TcpControlBits.Fin; }
} }
/// <summary>
/// The default validity check always returns true.
/// </summary>
protected override bool CalculateIsValid() protected override bool CalculateIsValid()
{ {
return Length >= HeaderMinimumLength && Length >= HeaderLength && Options.IsValid; return Length >= HeaderMinimumLength && Length >= HeaderLength && Options.IsValid;
......
...@@ -58,6 +58,9 @@ namespace PcapDotNet.Packets.Transport ...@@ -58,6 +58,9 @@ namespace PcapDotNet.Packets.Transport
return Equals(other as TcpOptionConnectionCountBase); return Equals(other as TcpOptionConnectionCountBase);
} }
/// <summary>
/// The hash code of the connection count option is the hash code of the option type xored with the hash code of the connection count.
/// </summary>
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode() ^ ConnectionCount.GetHashCode(); return base.GetHashCode() ^ ConnectionCount.GetHashCode();
......
...@@ -90,6 +90,9 @@ namespace PcapDotNet.Packets.Transport ...@@ -90,6 +90,9 @@ namespace PcapDotNet.Packets.Transport
return Equals(other as TcpOptionEcho); return Equals(other as TcpOptionEcho);
} }
/// <summary>
/// The hash code of the echo option is the hash code of the option type xored with the hash code info.
/// </summary>
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode() ^ Info.GetHashCode(); return base.GetHashCode() ^ Info.GetHashCode();
......
...@@ -97,6 +97,9 @@ namespace PcapDotNet.Packets.Transport ...@@ -97,6 +97,9 @@ namespace PcapDotNet.Packets.Transport
return Equals(other as TcpOptionEchoReply); return Equals(other as TcpOptionEchoReply);
} }
/// <summary>
/// The hash code of the echo reply option is the hash code of the option type xored with the hash code of the info.
/// </summary>
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode() ^ Info.GetHashCode(); return base.GetHashCode() ^ Info.GetHashCode();
......
...@@ -98,6 +98,9 @@ namespace PcapDotNet.Packets.Transport ...@@ -98,6 +98,9 @@ namespace PcapDotNet.Packets.Transport
return Equals(other as TcpOptionMd5Signature); return Equals(other as TcpOptionMd5Signature);
} }
/// <summary>
/// The hash code of the MD5 signature option is the hash code of the option type xored with the hash code of the signature.
/// </summary>
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode() ^ Data.BytesSequenceGetHashCode(); return base.GetHashCode() ^ Data.BytesSequenceGetHashCode();
......
...@@ -103,7 +103,10 @@ namespace PcapDotNet.Packets.Transport ...@@ -103,7 +103,10 @@ namespace PcapDotNet.Packets.Transport
return Equals(other as TcpOptionPartialOrderServiceProfile); return Equals(other as TcpOptionPartialOrderServiceProfile);
} }
public override int GetHashCode() /// <summary>
/// The hash code of the partial order service profile option is the hash code of the option type xored with a combination of the IsStart and IsEnd values.
/// </summary>
public override int GetHashCode()
{ {
return base.GetHashCode() ^ ((IsStart ? 1 : 0) << 1) ^ (IsEnd ? 1 : 0); return base.GetHashCode() ^ ((IsStart ? 1 : 0) << 1) ^ (IsEnd ? 1 : 0);
} }
......
...@@ -126,6 +126,9 @@ namespace PcapDotNet.Packets.Transport ...@@ -126,6 +126,9 @@ namespace PcapDotNet.Packets.Transport
return Equals(other as TcpOptionSelectiveAcknowledgment); return Equals(other as TcpOptionSelectiveAcknowledgment);
} }
/// <summary>
/// The hash code of the selective acknowledgement option is the hash code of the option type xored with all the hash codes of the blocks.
/// </summary>
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode() ^ Blocks.SequenceGetHashCode(); return base.GetHashCode() ^ Blocks.SequenceGetHashCode();
......
...@@ -105,6 +105,9 @@ namespace PcapDotNet.Packets.Transport ...@@ -105,6 +105,9 @@ namespace PcapDotNet.Packets.Transport
return Equals(other as TcpOptionTimestamp); return Equals(other as TcpOptionTimestamp);
} }
/// <summary>
/// The hash code of the timestamp option is the hash code of the option type xored with the hash code of the timestamp echo reply.
/// </summary>
public override int GetHashCode() public override int GetHashCode()
{ {
return base.GetHashCode() ^ TimestampEchoReply.GetHashCode(); return base.GetHashCode() ^ TimestampEchoReply.GetHashCode();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment