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
}
/// <summary>
/// Returns a hash code by xoring all the bytes.
/// Each byte is xored with the next 8 bits of the integer.
/// Returns a string by converting all the bytes to a hexadecimal string.
/// </summary>
/// <param name="sequence">The bytes to xor.</param>
/// <returns>The hash code resulted by xoring all the bytes.</returns>
/// <param name="sequence">The bytes to convert to a string.</param>
/// <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)
{
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 @@
<ItemGroup>
<None Include="..\PcapDotNet.snk" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="CodeAnalysisDictionary.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.
......
using System;
using System.Collections.ObjectModel;
using PcapDotNet.Packets.Ethernet;
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.
/// 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
/// their actual lengths are determined by the hardware & protocol length fields.
/// their actual lengths are determined by the hardware &amp; protocol length fields.
/// <pre>
/// +-----+------------------------+------------------------+-----------------------------------------------+
/// | bit | 0-7 | 8-15 | 16-31 |
......@@ -42,8 +43,14 @@ namespace PcapDotNet.Packets.Arp
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;
/// <summary>
/// The number of bytes in the ARP header.
/// </summary>
public int HeaderLength
{
get { return GetHeaderLength(HardwareLength, ProtocolLength); }
......@@ -92,36 +99,39 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// Hardware address of the sender.
/// </summary>
public byte[] SenderHardwareAddress
public ReadOnlyCollection<byte> SenderHardwareAddress
{
get { return ReadBytes(Offset.SenderHardwareAddress, HardwareLength); }
get { return new ReadOnlyCollection<byte>(ReadBytes(Offset.SenderHardwareAddress, HardwareLength)); }
}
/// <summary>
/// Protocol address of the sender.
/// </summary>
public byte[] SenderProtocolAddress
public ReadOnlyCollection<byte> SenderProtocolAddress
{
get { return ReadBytes(OffsetSenderProtocolAddress, ProtocolLength); }
get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetSenderProtocolAddress, ProtocolLength)); }
}
/// <summary>
/// Hardware address of the intended receiver.
/// This field is ignored in requests.
/// </summary>
public byte[] TargetHardwareAddress
public ReadOnlyCollection<byte> TargetHardwareAddress
{
get { return ReadBytes(OffsetTargetHardwareAddress, HardwareLength); }
get { return new ReadOnlyCollection<byte>(ReadBytes(OffsetTargetHardwareAddress, HardwareLength)); }
}
/// <summary>
/// Protocol address of the intended receiver.
/// </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()
{
return Length >= HeaderBaseLength && Length == HeaderLength;
......
namespace PcapDotNet.Packets.Arp
{
/// <summary>
/// The data link layer protocol of the ARP protocol.
/// </summary>
public enum ArpHardwareType : ushort
{
/// <summary>
/// Invalid hardware type
/// </summary>
None = 0,
/// <summary>
/// Ethernet (10Mb)
/// </summary>
......@@ -35,17 +43,17 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// ARCNET
/// </summary>
Arcnet = 7,
AttachedResourceComputerNetwork = 7,
/// <summary>
/// Hyperchannel
/// </summary>
Hyperchannel = 8,
HyperChannel = 8,
/// <summary>
/// Lanstar
/// </summary>
Lanstar = 9,
LanStar = 9,
/// <summary>
/// Autonet Short Address
......@@ -70,7 +78,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// SMDS
/// </summary>
Smds = 14,
SwitchedMultimegabitDataService = 14,
/// <summary>
/// Frame Relay
......@@ -85,7 +93,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// HDLC
/// </summary>
Hdlc = 17,
HighLevelDataLinkControl = 17,
/// <summary>
/// Fibre Channel
......@@ -110,7 +118,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// MIL-STD-188-220
/// </summary>
MilStd188_220 = 22,
MilStd188Hyphen220 = 22,
/// <summary>
/// Metricom
......@@ -120,12 +128,12 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// IEEE 1394.1995
/// </summary>
Ieee1394_1995 = 24,
Ieee1394Dot1995 = 24,
/// <summary>
/// MAPOS
/// </summary>
Mapos = 25,
MultipleAccessOverSynchronousOpticalNetworkingOrSynchronousDigitalHierarchy = 25,
/// <summary>
/// Twinaxial
......@@ -135,7 +143,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// EUI-64
/// </summary>
Eui64 = 27,
ExtendedUniqueIdentifier64 = 27,
/// <summary>
/// HIPARP
......@@ -145,7 +153,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// IP and ARP over ISO 7816-3
/// </summary>
IpAndArpOverIso7816_3 = 29,
IpAndArpOverIso7816Hyphen3 = 29,
/// <summary>
/// ARPSec
......
namespace PcapDotNet.Packets.Arp
{
/// <summary>
/// Specifies the operation the ARP sender is performing.
/// </summary>
public enum ArpOperation : ushort
{
/// <summary>
/// Invalid operation.
/// </summary>
None = 0,
/// <summary>
/// [RFC826][RFC5227]
/// </summary>
......@@ -68,7 +76,7 @@ namespace PcapDotNet.Packets.Arp
/// <summary>
/// [RFC2176]
/// </summary>
MultipleAccessOverSonetOrSdhUnarp = 23,
MultipleAccessOverSynchronousOpticalNetworkingOrSynchronousDigitalHierarchyUnsolicitedArp = 23,
/// <summary>
/// [RFC5494]
......
......@@ -38,6 +38,15 @@
<Word>genser</Word>
<Word>nsa</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>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
......
......@@ -152,6 +152,12 @@ namespace PcapDotNet.Packets
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)
{
return Buffer.ReadBytes(StartOffset + offset, length);
......
......@@ -31,6 +31,9 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary>
public const int HeaderLength = 14;
/// <summary>
/// The broadcast MAC address (FF:FF:FF:FF:FF:FF).
/// </summary>
public static MacAddress BroadcastAddress
{
get { return _broadcastAddress; }
......@@ -98,6 +101,9 @@ namespace PcapDotNet.Packets.Ethernet
}
}
/// <summary>
/// The Ethernet payload as an ARP datagram.
/// </summary>
public ArpDatagram Arp
{
get
......
......@@ -30,6 +30,21 @@ namespace PcapDotNet.Packets
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,
MacAddress ethernetSource,
EthernetType arpProtocolType, ArpOperation arpOperation,
......
......@@ -230,6 +230,9 @@ namespace PcapDotNet.Packets.Transport
get { return (ControlBits & TcpControlBits.Fin) == TcpControlBits.Fin; }
}
/// <summary>
/// The default validity check always returns true.
/// </summary>
protected override bool CalculateIsValid()
{
return Length >= HeaderMinimumLength && Length >= HeaderLength && Options.IsValid;
......
......@@ -58,6 +58,9 @@ namespace PcapDotNet.Packets.Transport
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()
{
return base.GetHashCode() ^ ConnectionCount.GetHashCode();
......
......@@ -90,6 +90,9 @@ namespace PcapDotNet.Packets.Transport
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()
{
return base.GetHashCode() ^ Info.GetHashCode();
......
......@@ -97,6 +97,9 @@ namespace PcapDotNet.Packets.Transport
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()
{
return base.GetHashCode() ^ Info.GetHashCode();
......
......@@ -98,6 +98,9 @@ namespace PcapDotNet.Packets.Transport
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()
{
return base.GetHashCode() ^ Data.BytesSequenceGetHashCode();
......
......@@ -103,7 +103,10 @@ namespace PcapDotNet.Packets.Transport
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);
}
......
......@@ -126,6 +126,9 @@ namespace PcapDotNet.Packets.Transport
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()
{
return base.GetHashCode() ^ Blocks.SequenceGetHashCode();
......
......@@ -105,6 +105,9 @@ namespace PcapDotNet.Packets.Transport
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()
{
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