Commit c04ed979 authored by Brickner_cp's avatar Brickner_cp

IpV4

Code Analysis
parent f96304cf
......@@ -30,7 +30,27 @@
<WRAP_LIMIT>150</WRAP_LIMIT>
</FormatSettings>
<UsingsSettings />
<Naming2 />
<Naming2>
<ExceptionName IsNull="False">
</ExceptionName>
<OverrideDefaultSettings>True</OverrideDefaultSettings>
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces" />
<PredefinedRule Inspect="True" Prefix="I" Suffix="" Style="AaBb" ElementKind="Interfaces" />
<PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="LocalConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Parameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PublicFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateInstanceFields" />
<PredefinedRule Inspect="True" Prefix="_" Suffix="" Style="aaBb" ElementKind="PrivateStaticFields" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Constants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateConstants" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="StaticReadonly" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="PrivateStaticReadonly" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="EnumMember" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="Other" />
</Naming2>
</CSharp>
<VB>
<FormatSettings>
......
<?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
......@@ -27,6 +27,8 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>true</RunCodeAnalysis>
<DocumentationFile>..\..\bin\Debug\PcapDotNet.Base.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -35,6 +37,8 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<RunCodeAnalysis>true</RunCodeAnalysis>
<DocumentationFile>..\..\bin\Release\PcapDotNet.Base.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
......@@ -57,6 +61,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.Reflection;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
......@@ -34,3 +35,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: CLSCompliant(true)]
\ No newline at end of file
......@@ -30,8 +30,34 @@ namespace PcapDotNet.Base
return _mostSignificant << 16 + _leastSignificant;
}
public bool Equals(UInt24 other)
{
return other._mostSignificant == _mostSignificant && other._leastSignificant == _leastSignificant;
}
public override bool Equals(object obj)
{
return (obj is UInt24) &&
Equals((UInt24)obj);
}
public static bool operator ==(UInt24 value1, UInt24 value2)
{
return value1.Equals(value2);
}
public static bool operator !=(UInt24 value1, UInt24 value2)
{
return !(value1 == value2);
}
public override int GetHashCode()
{
return this;
}
private readonly byte _mostSignificant;
private readonly ushort _leastSignificant;
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WinPcapDotNet.Console</RootNamespace>
<AssemblyName>WinPcapDotNet.Console</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PcapDotNet.Core\WinPCapDotNet.Core.vcproj">
<Project>{89C63BE1-AF9A-472E-B256-A4F56B1655A7}</Project>
<Name>PcapDotNet.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using PcapDotNet;
using PcapDotNet.Core;
namespace WinPcapDotNet.Console
{
class Program
{
/// <summary>
///
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PcapDotNet.Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PcapDotNet.Console")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("97b50e85-bf8b-4d86-8e5c-3f84732e9a3d")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
......@@ -78,7 +78,7 @@ namespace PcapDotNet.Core.Test
byte ipV4TypeOfService = random.NextByte();
ushort ipV4Identification = random.NextUShort();
byte ipV4Ttl = random.NextByte();
IpV4FragmentationFlags ipV4FragmentationFlags = random.NextEnum<IpV4FragmentationFlags>();
IpV4FragmentationOptions ipV4FragmentationFlags = random.NextEnum<IpV4FragmentationOptions>();
ushort ipV4FragmentationOffset = random.NextUShort();
IpV4Fragmentation ipV4Fragmentation = new IpV4Fragmentation(ipV4FragmentationFlags, ipV4FragmentationOffset);
IpV4Protocol ipV4Protocol = random.NextEnum<IpV4Protocol>();
......@@ -90,7 +90,7 @@ namespace PcapDotNet.Core.Test
random.NextBytes(ipV4PayloadBuffer);
Datagram ipV4Payload = new Datagram(ipV4PayloadBuffer);
Packet packet = PacketBuilder.IpV4(DateTime.Now,
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
ethernetSource, ethernetDestination, ethernetType,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4Ttl, ipV4Protocol,
ipV4Source, ipV4Destination, ipV4Options,
......
......@@ -93,7 +93,7 @@
/>
<Tool
Name="VCFxCopTool"
Rules="-Microsoft.Design#CA1021;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027"
Rules="-Microsoft.Design#CA1021;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Reliability#CA2004"
EnableFxCop="true"
Dictionaries="CodeAnalysisDictionary.xml"
/>
......@@ -103,7 +103,7 @@
<Tool
Name="VCPostBuildEventTool"
Description="Build Release Files"
CommandLine="cd $(OutDir)&#x0D;&#x0A;zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml"
CommandLine="cd $(OutDir)&#x0D;&#x0A;zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml&#x0D;&#x0A;"
/>
</Configuration>
<Configuration
......@@ -186,7 +186,7 @@
<Tool
Name="VCPostBuildEventTool"
Description="Build Release Files"
CommandLine="cd $(OutDir)&#x0D;&#x0A;zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml"
CommandLine="cd $(OutDir)&#x0D;&#x0A;zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml&#x0D;&#x0A;"
/>
</Configuration>
</Configurations>
......@@ -208,7 +208,7 @@
/>
<ProjectReference
ReferencedProjectIdentifier="{8A184AF5-E46C-482C-81A3-76D8CE290104}"
RelativePathToProject=".\Packets\Packets.csproj"
RelativePathToProject=".\PcapDotNet.Packets\PcapDotNet.Packets.csproj"
/>
</References>
<Files>
......
......@@ -82,7 +82,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(IpV4Datagram.HeaderMinimumLength, packet.Ethernet.IpV4.HeaderLength, "IP HeaderLength");
Assert.AreEqual(0, packet.Ethernet.IpV4.TypeOfService, "IP TypeOfService");
Assert.AreEqual(packet.Length - EthernetDatagram.HeaderLength, packet.Ethernet.IpV4.TotalLength, "IP TotalLength");
Assert.AreEqual(new IpV4Fragmentation(IpV4FragmentationFlags.DontFragment, 0), packet.Ethernet.IpV4.Fragmentation, "IP Fragmentation");
Assert.AreEqual(new IpV4Fragmentation(IpV4FragmentationOptions.DoNotFragment, 0), packet.Ethernet.IpV4.Fragmentation, "IP Fragmentation");
Assert.AreEqual(128, packet.Ethernet.IpV4.Ttl, "IP Ttl");
Assert.AreEqual(IpV4Protocol.Tcp, packet.Ethernet.IpV4.Protocol, "IP Protocol");
Assert.AreEqual(0x9010, packet.Ethernet.IpV4.HeaderChecksum, "IP HeaderChecksum");
......@@ -106,9 +106,9 @@ namespace PcapDotNet.Packets.Test
byte ipV4TypeOfService = random.NextByte();
ushort ipV4Identification = random.NextUShort();
byte ipV4Ttl = random.NextByte();
IpV4FragmentationFlags ipV4FragmentationFlags = random.NextEnum<IpV4FragmentationFlags>();
IpV4FragmentationOptions ipV4FragmentationOptions = random.NextEnum<IpV4FragmentationOptions>();
ushort ipV4FragmentationOffset = random.NextUShort();
IpV4Fragmentation ipV4Fragmentation = new IpV4Fragmentation(ipV4FragmentationFlags, ipV4FragmentationOffset);
IpV4Fragmentation ipV4Fragmentation = new IpV4Fragmentation(ipV4FragmentationOptions, ipV4FragmentationOffset);
IpV4Protocol ipV4Protocol = random.NextEnum<IpV4Protocol>();
IpV4Address ipV4Source = new IpV4Address(random.NextUInt());
IpV4Address ipV4Destination = new IpV4Address(random.NextUInt());
......@@ -118,7 +118,7 @@ namespace PcapDotNet.Packets.Test
random.NextBytes(ipV4PayloadBuffer);
Datagram ipV4Payload = new Datagram(ipV4PayloadBuffer);
Packet packet = PacketBuilder.IpV4(DateTime.Now,
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
ethernetSource, ethernetDestination, ethernetType,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4Ttl, ipV4Protocol,
ipV4Source, ipV4Destination, ipV4Options,
......@@ -139,7 +139,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(packet.Length - EthernetDatagram.HeaderLength, packet.Ethernet.IpV4.TotalLength, "IP TotalLength");
Assert.AreEqual(ipV4Identification, packet.Ethernet.IpV4.Identification, "IP Identification");
Assert.AreEqual(ipV4Fragmentation, packet.Ethernet.IpV4.Fragmentation, "IP Fragmentation");
Assert.AreEqual(ipV4Fragmentation.Flags, packet.Ethernet.IpV4.Fragmentation.Flags, "IP Fragmentation");
Assert.AreEqual(ipV4Fragmentation.Options, packet.Ethernet.IpV4.Fragmentation.Options, "IP Fragmentation");
Assert.AreEqual(ipV4Fragmentation.Offset, packet.Ethernet.IpV4.Fragmentation.Offset, "IP Fragmentation");
Assert.AreEqual(ipV4Ttl, packet.Ethernet.IpV4.Ttl, "IP Ttl");
Assert.AreEqual(ipV4Protocol, packet.Ethernet.IpV4.Protocol, "IP Protocol");
......
......@@ -5,7 +5,35 @@
<!--Word>cb</Word-->
</Unrecognized>
<Recognized>
<Word>Endianity</Word>
<Word>pcap</Word>
<Word>endianity</Word>
<Word>prespecified</Word>
<Word>ttl</Word>
<Word>mmmm</Word> <!-- Still couldn't find out what this mean -->
<Word>satnet</Word>
<Word>bbn</Word> <!-- Probably BBN Technologies (originally Bolt, Beranek and Newman) -->
<Word>aris</Word>
<Word>ax</Word>
<Word>cbt</Word>
<Word>cftp</Word> <!-- maybe Configurable Fault Tolerant Processor -->
<Word>dcn</Word>
<Word>emcon</Word>
<Word>fibre</Word>
<Word>gmtp</Word>
<Word>iplt</Word>
<Word>ipsilon</Word> <!-- As in Ipsilon Networks -->
<Word>kryptolan</Word>
<Word>internodal</Word>
<Word>qnx</Word> <!-- www.qnx.com -->
<Word>expak</Word>
<Word>sitara</Word>
<Word>tcf</Word>
<Word>ttp</Word>
<Word>lite</Word>
<Word>uti</Word>
<Word>rcc</Word>
<Word>internetwork</Word>
<Word>multiprotocol</Word>
</Recognized>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
......@@ -20,6 +48,9 @@
<Acronyms>
<CasingExceptions>
<Acronym>Ip</Acronym>
<Acronym>Sm</Acronym>
<Acronym>Nd</Acronym>
<Acronym>Ns</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
\ No newline at end of file
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace PcapDotNet.Packets
{
public class Datagram : IEquatable<Datagram>
public class Datagram : IEquatable<Datagram>, IEnumerable<byte>
{
public Datagram(byte[] buffer)
: this(buffer, 0, buffer.Length)
......@@ -46,6 +49,17 @@ namespace PcapDotNet.Packets
return true;
}
public IEnumerator<byte> GetEnumerator()
{
for (int i = 0; i != Length; ++i)
yield return this[i];
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool Equals(Datagram other)
{
if (Length != other.Length)
......@@ -65,6 +79,13 @@ namespace PcapDotNet.Packets
return Equals(obj as Datagram);
}
public override int GetHashCode()
{
int i = 0;
return Length.GetHashCode() ^
this.Aggregate(0, (value, b) => value ^ (b << (8 * (i++ % 4))));
}
internal void Write(byte[] buffer, int offset)
{
System.Buffer.BlockCopy(_buffer, StartOffset, buffer, offset, Length);
......@@ -87,6 +108,7 @@ namespace PcapDotNet.Packets
return _buffer.ReadUShort(StartOffset + offset, endianity);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "uint")]
protected uint ReadUInt(int offset, Endianity endianity)
{
return _buffer.ReadUInt(StartOffset + offset, endianity);
......
using System.Globalization;
using System.Text;
namespace PcapDotNet.Packets
......@@ -12,10 +13,10 @@ namespace PcapDotNet.Packets
public IpV4Address(string value)
{
string[] values = value.Split('.');
_value = (uint)((byte.Parse(values[0]) << 24) +
(byte.Parse(values[1]) << 16) +
(byte.Parse(values[2]) << 8) +
(byte.Parse(values[3])));
_value = (uint)((byte.Parse(values[0], CultureInfo.InvariantCulture) << 24) +
(byte.Parse(values[1], CultureInfo.InvariantCulture) << 16) +
(byte.Parse(values[2], CultureInfo.InvariantCulture) << 8) +
(byte.Parse(values[3], CultureInfo.InvariantCulture)));
}
public static IpV4Address Zero
......@@ -48,14 +49,14 @@ namespace PcapDotNet.Packets
Equals((IpV4Address)obj));
}
public static bool operator ==(IpV4Address ipV4Address1, IpV4Address ipV4Address2)
public static bool operator ==(IpV4Address value1, IpV4Address value2)
{
return ipV4Address1.Equals(ipV4Address2);
return value1.Equals(value2);
}
public static bool operator !=(IpV4Address ipV4Address1, IpV4Address ipV4Address2)
public static bool operator !=(IpV4Address value1, IpV4Address value2)
{
return !(ipV4Address1 == ipV4Address2);
return !(value1 == value2);
}
public override int GetHashCode()
......
......@@ -9,14 +9,14 @@ namespace PcapDotNet.Packets
get { return _none; }
}
public IpV4Fragmentation(IpV4FragmentationFlags flags, ushort offset)
: this((ushort)((ushort)flags | (offset / 8)))
public IpV4Fragmentation(IpV4FragmentationOptions options, ushort offset)
: this((ushort)((ushort)options | (offset / 8)))
{
}
public IpV4FragmentationFlags Flags
public IpV4FragmentationOptions Options
{
get { return (IpV4FragmentationFlags)(_value & 0xE000); }
get { return (IpV4FragmentationOptions)(_value & 0xE000); }
}
public ushort Offset
......@@ -35,6 +35,21 @@ namespace PcapDotNet.Packets
Equals((IpV4Fragmentation)obj));
}
public static bool operator ==(IpV4Fragmentation value1, IpV4Fragmentation value2)
{
return value1.Equals(value2);
}
public static bool operator !=(IpV4Fragmentation value1, IpV4Fragmentation value2)
{
return !(value1 == value2);
}
public override int GetHashCode()
{
return _value;
}
internal IpV4Fragmentation(ushort value)
{
_value = value;
......@@ -45,7 +60,7 @@ namespace PcapDotNet.Packets
buffer.Write(offset, _value, Endianity.Big);
}
private static readonly IpV4Fragmentation _none = new IpV4Fragmentation(IpV4FragmentationFlags.None, 0);
private static readonly IpV4Fragmentation _none = new IpV4Fragmentation(IpV4FragmentationOptions.None, 0);
private readonly ushort _value;
}
}
\ No newline at end of file
......@@ -3,11 +3,11 @@ using System;
namespace PcapDotNet.Packets
{
[Flags]
public enum IpV4FragmentationFlags : ushort
public enum IpV4FragmentationOptions : ushort
{
None = 0x0 << 13,
Reserved = 0x4 << 13,
DontFragment = 0x2 << 13,
// Reserved = 0x4 << 13,
DoNotFragment = 0x2 << 13,
MoreFragments = 0x1 << 13
}
}
\ No newline at end of file
......@@ -36,6 +36,11 @@ namespace PcapDotNet.Packets
return Equals(obj as IpV4Option);
}
public override int GetHashCode()
{
return (byte)OptionType;
}
protected IpV4Option(IpV4OptionType type)
{
_type = type;
......
......@@ -38,6 +38,13 @@ namespace PcapDotNet.Packets
return Equals(other as IpV4OptionRoute);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
PointedAddressIndex ^
_addresses.Aggregate(0, (value, address) => value ^ address.GetHashCode());
}
internal override void Write(byte[] buffer, ref int offset)
{
base.Write(buffer, ref offset);
......
......@@ -63,6 +63,14 @@ namespace PcapDotNet.Packets
return Equals(other as IpV4OptionSecurity);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
(((ushort)Level << 16) | Compartments) ^
(HandlingRestrictions << 16) ^
TransmissionControlCode.GetHashCode();
}
internal static IpV4OptionSecurity ReadOptionSecurity(byte[] buffer, ref int offset, int length)
{
if (length < OptionLength - 1)
......
......@@ -4,9 +4,9 @@ namespace PcapDotNet.Packets
{
Unclassified = 0x0000,
Confidential = 0xF135,
EFTO = 0x789A,
MMMM = 0xBC4D,
PROG = 0x5E26,
EncryptedForTransmissionOnly = 0x789A,
Mmmm = 0xBC4D,
Prog = 0x5E26,
Restricted = 0xAF13,
Secret = 0xD788,
TopSecret = 0x6BC5
......
......@@ -39,6 +39,12 @@ namespace PcapDotNet.Packets
return Equals(other as IpV4OptionStreamIdentifier);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
Identifier.GetHashCode();
}
internal static IpV4OptionStreamIdentifier ReadOptionStreamIdentifier(byte[] buffer, ref int offset, int length)
{
if (length < OptionLength - 1)
......
......@@ -53,6 +53,14 @@ namespace PcapDotNet.Packets
return Equals(other as IpV4OptionTimestamp);
}
public override int GetHashCode()
{
return base.GetHashCode() ^
((byte)TimestampType << 16) ^
(Overflow << 8) ^
PointedIndex;
}
internal static IpV4OptionTimestamp ReadOptionTimestamp(byte[] buffer, ref int offset, int length)
{
if (length < OptionMinimumLength - 1)
......
......@@ -12,6 +12,14 @@ namespace PcapDotNet.Packets
_addressesAndTimestamps = addressesAndTimestamps;
}
public override int GetHashCode()
{
return base.GetHashCode() ^
_addressesAndTimestamps.Aggregate(0, (value, pair) => value ^
pair.Key.GetHashCode() ^
pair.Value.GetHashCode());
}
internal static IpV4OptionTimestampAndAddress Read(IpV4OptionTimestampType timestampType, byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues)
{
if (numValues % 2 != 0)
......
......@@ -11,6 +11,12 @@ namespace PcapDotNet.Packets
_timestamps = timestamps;
}
public override int GetHashCode()
{
return base.GetHashCode() ^
_timestamps.Aggregate(0, (value, timestamp) => value ^ timestamp.GetHashCode());
}
internal static IpV4OptionTimestampOnly Read(byte overflow, byte pointedIndex, byte[] buffer, ref int offset, int numValues)
{
TimeSpan[] timestamps = new TimeSpan[numValues];
......
......@@ -2,7 +2,6 @@ using System;
namespace PcapDotNet.Packets
{
[Flags]
public enum IpV4OptionTimestampType : byte
{
TimestampOnly = 0,
......
......@@ -75,6 +75,12 @@ namespace PcapDotNet.Packets
return Equals(obj as IpV4Options);
}
public override int GetHashCode()
{
return Length.GetHashCode() ^
_options.Aggregate(0, (value, option) => value ^ option.GetHashCode());
}
internal void Write(byte[] buffer, int offset)
{
int offsetEnd = offset + Length;
......
......@@ -27,6 +27,7 @@ namespace PcapDotNet.Packets
return (ushort)ReadShort(buffer, offset, endianity);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "ushort")]
public static ushort ReadUShort(this byte[] buffer, ref int offset, Endianity endianity)
{
ushort result = ReadUShort(buffer, offset, endianity);
......@@ -55,6 +56,7 @@ namespace PcapDotNet.Packets
return (uint)ReadInt(buffer, offset, endianity);
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "uint")]
public static uint ReadUInt(this byte[] buffer, ref int offset, Endianity endianity)
{
uint result = ReadUInt(buffer, offset, endianity);
......
......@@ -14,7 +14,7 @@ namespace PcapDotNet.Packets
return new Packet(buffer, timestamp, new DataLink(DataLinkKind.Ethernet));
}
public static Packet IpV4(DateTime timestamp,
public static Packet EthernetIpV4(DateTime timestamp,
MacAddress ethernetSource, MacAddress ethernetDestination, EthernetType ethernetType,
byte ipV4TypeOfService, ushort ipV4Identification, IpV4Fragmentation ipV4Fragmentation,
byte ipV4Ttl, IpV4Protocol ipV4Protocol,
......
......@@ -30,7 +30,8 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1028</CodeAnalysisRules>
<CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Naming#CA1710</CodeAnalysisRules>
<DocumentationFile>..\..\bin\Debug\PcapDotNet.Packets.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -41,7 +42,8 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Design#CA1028</CodeAnalysisRules>
<CodeAnalysisRules>-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Naming#CA1710</CodeAnalysisRules>
<DocumentationFile>..\..\bin\Release\PcapDotNet.Packets.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
......@@ -68,7 +70,7 @@
<Compile Include="IpV4\IpV4Address.cs" />
<Compile Include="IpV4\IpV4Datagram.cs" />
<Compile Include="IpV4\IpV4Fragmentation.cs" />
<Compile Include="IpV4\IpV4FragmentationFlags.cs" />
<Compile Include="IpV4\IpV4FragmentationOptions.cs" />
<Compile Include="IpV4\IpV4Option.cs" />
<Compile Include="IpV4\IpV4OptionEndOfOptionsList.cs" />
<Compile Include="IpV4\IpV4OptionLooseSourceRouting.cs" />
......

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Console", "PcapDotNet.Console\PcapDotNet.Console.csproj", "{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PcapDotNet.Core", "PcapDotNet.Core\WinPCapDotNet.Core.vcproj", "{89C63BE1-AF9A-472E-B256-A4F56B1655A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Core.Test", "PcapDotNet.Core.Test\PcapDotNet.Core.Test.csproj", "{045A6460-C260-4CDA-8030-FD19A0086C95}"
......@@ -26,34 +24,31 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Packets.Test", "
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 9
SccNumberOfProjects = 8
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs06.codeplex.com/
SccLocalPath0 = .
SccProjectUniqueName1 = PcapDotNet.Core\\WinPCapDotNet.Core.vcproj
SccProjectName1 = PcapDotNet.Core
SccLocalPath1 = PcapDotNet.Core
SccProjectUniqueName2 = PcapDotNet.Console\\PcapDotNet.Console.csproj
SccProjectName2 = PcapDotNet.Console
SccLocalPath2 = PcapDotNet.Console
SccProjectUniqueName3 = PcapDotNet.Core.Test\\PcapDotNet.Core.Test.csproj
SccProjectName3 = PcapDotNet.Core.Test
SccLocalPath3 = PcapDotNet.Core.Test
SccProjectUniqueName4 = PcapDotNet.TestUtils\\PcapDotNet.TestUtils.csproj
SccProjectName4 = PcapDotNet.TestUtils
SccLocalPath4 = PcapDotNet.TestUtils
SccProjectUniqueName5 = PcapDotNet.Packets.TestUtils\\PcapDotNet.Packets.TestUtils.csproj
SccProjectName5 = PcapDotNet.Packets.TestUtils
SccLocalPath5 = PcapDotNet.Packets.TestUtils
SccProjectUniqueName6 = PcapDotNet.Base\\PcapDotNet.Base.csproj
SccProjectName6 = PcapDotNet.Base
SccLocalPath6 = PcapDotNet.Base
SccProjectUniqueName7 = PcapDotNet.Packets.Test\\PcapDotNet.Packets.Test.csproj
SccProjectName7 = PcapDotNet.Packets.Test
SccLocalPath7 = PcapDotNet.Packets.Test
SccProjectUniqueName8 = PcapDotNet.Packets\\PcapDotNet.Packets.csproj
SccProjectName8 = PcapDotNet.Packets
SccLocalPath8 = PcapDotNet.Packets
SccProjectUniqueName2 = PcapDotNet.Core.Test\\PcapDotNet.Core.Test.csproj
SccProjectName2 = PcapDotNet.Core.Test
SccLocalPath2 = PcapDotNet.Core.Test
SccProjectUniqueName3 = PcapDotNet.TestUtils\\PcapDotNet.TestUtils.csproj
SccProjectName3 = PcapDotNet.TestUtils
SccLocalPath3 = PcapDotNet.TestUtils
SccProjectUniqueName4 = PcapDotNet.Packets.TestUtils\\PcapDotNet.Packets.TestUtils.csproj
SccProjectName4 = PcapDotNet.Packets.TestUtils
SccLocalPath4 = PcapDotNet.Packets.TestUtils
SccProjectUniqueName5 = PcapDotNet.Base\\PcapDotNet.Base.csproj
SccProjectName5 = PcapDotNet.Base
SccLocalPath5 = PcapDotNet.Base
SccProjectUniqueName6 = PcapDotNet.Packets.Test\\PcapDotNet.Packets.Test.csproj
SccProjectName6 = PcapDotNet.Packets.Test
SccLocalPath6 = PcapDotNet.Packets.Test
SccProjectUniqueName7 = PcapDotNet.Packets\\PcapDotNet.Packets.csproj
SccProjectName7 = PcapDotNet.Packets
SccLocalPath7 = PcapDotNet.Packets
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = PcapDotNet.vsmdi
......@@ -67,18 +62,6 @@ Global
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Debug|Win32.ActiveCfg = Debug|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Debug|Win32.Build.0 = Debug|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Release|Any CPU.Build.0 = Release|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Release|Win32.ActiveCfg = Release|Any CPU
{5B4E80EB-DED5-4F20-871A-D9567F3F79DD}.Release|Win32.Build.0 = Release|Any CPU
{89C63BE1-AF9A-472E-B256-A4F56B1655A7}.Debug|Any CPU.ActiveCfg = Debug|Win32
{89C63BE1-AF9A-472E-B256-A4F56B1655A7}.Debug|Any CPU.Build.0 = Debug|Win32
{89C63BE1-AF9A-472E-B256-A4F56B1655A7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
......
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