Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
87c38e83
Commit
87c38e83
authored
Feb 27, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code Analysis and Documentation - 352 warnings left.
Added Sandcastle Help File Builder Project file.
parent
63aad8a4
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
257 additions
and
75 deletions
+257
-75
PcapDotNet.shfbproj
PcapDotNet/doc/PcapDotNet.shfbproj
+47
-0
IEnumerableExtensions.cs
PcapDotNet/src/PcapDotNet.Base/IEnumerableExtensions.cs
+1
-0
LivePacketDeviceExtensions.cs
.../PcapDotNet.Core.Extensions/LivePacketDeviceExtensions.cs
+3
-0
ArpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
+5
-16
IgmpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IgmpTests.cs
+8
-9
RandomPacketsExtensions.cs
...c/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
+5
-13
ArpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Arp/ArpDatagram.cs
+9
-9
ArpLayer.cs
PcapDotNet/src/PcapDotNet.Packets/Arp/ArpLayer.cs
+76
-8
IArpPreviousLayer.cs
PcapDotNet/src/PcapDotNet.Packets/Arp/IArpPreviousLayer.cs
+4
-1
Datagram.cs
PcapDotNet/src/PcapDotNet.Packets/Datagram.cs
+3
-0
EthernetDatagram.cs
...otNet/src/PcapDotNet.Packets/Ethernet/EthernetDatagram.cs
+3
-0
IEthernetNextLayer.cs
...Net/src/PcapDotNet.Packets/Ethernet/IEthernetNextLayer.cs
+8
-0
MacAddress.cs
PcapDotNet/src/PcapDotNet.Packets/Ethernet/MacAddress.cs
+1
-1
ILayer.cs
PcapDotNet/src/PcapDotNet.Packets/ILayer.cs
+26
-0
IcmpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagram.cs
+1
-1
IcmpRouterAdvertisementDatagram.cs
...capDotNet.Packets/Icmp/IcmpRouterAdvertisementDatagram.cs
+1
-2
IcmpRouterAdvertisementLayer.cs
...c/PcapDotNet.Packets/Icmp/IcmpRouterAdvertisementLayer.cs
+9
-1
IgmpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
+2
-6
IgmpQueryVersion3Layer.cs
...Net/src/PcapDotNet.Packets/Igmp/IgmpQueryVersion3Layer.cs
+10
-2
IgmpReportVersion3Layer.cs
...et/src/PcapDotNet.Packets/Igmp/IgmpReportVersion3Layer.cs
+17
-1
IpV6Address.cs
PcapDotNet/src/PcapDotNet.Packets/IpV6/IpV6Address.cs
+2
-2
Layer.cs
PcapDotNet/src/PcapDotNet.Packets/Layer.cs
+13
-0
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+3
-3
No files found.
PcapDotNet/doc/PcapDotNet.shfbproj
0 → 100644
View file @
87c38e83
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<!-- The configuration and platform will be used to determine which
assemblies to include from solution and project documentation
sources -->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{980d69c5-143d-4841-987f-ffd333557569}</ProjectGuid>
<SHFBSchemaVersion>1.8.0.0</SHFBSchemaVersion>
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual
Studio adds them anyway -->
<AssemblyName>Documentation</AssemblyName>
<RootNamespace>Documentation</RootNamespace>
<Name>Documentation</Name>
<!-- SHFB properties -->
<OutputPath>.\Help\</OutputPath>
<HtmlHelpName>Pcap.Net</HtmlHelpName>
<DocumentationSources>
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Base.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Base.xml" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.Extensions.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.Extensions.xml" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Core.xml" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Packets.dll" />
<DocumentationSource sourceFile="..\bin\Release\PcapDotNet.Packets.XML" />
</DocumentationSources>
<FrameworkVersion>3.5</FrameworkVersion>
<Language>en-US</Language>
<Preliminary>False</Preliminary>
<CppCommentsFixup>True</CppCommentsFixup>
<HelpTitle>Pcap.Net Documented Class Library</HelpTitle>
<MissingTags>None</MissingTags>
<HelpFileVersion>0.4.0.0</HelpFileVersion>
<RootNamespaceContainer>False</RootNamespaceContainer>
<ShowFeedbackControl>False</ShowFeedbackControl>
</PropertyGroup>
<!-- There are no properties for these two groups but they need to appear in
order for Visual Studio to perform the build. -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<!-- Import the SHFB build targets -->
<Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" />
</Project>
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Base/IEnumerableExtensions.cs
View file @
87c38e83
using
System
;
using
System.Collections.ObjectModel
;
using
System.Globalization
;
using
System.Linq
;
using
System.Collections
;
...
...
PcapDotNet/src/PcapDotNet.Core.Extensions/LivePacketDeviceExtensions.cs
View file @
87c38e83
...
...
@@ -6,6 +6,9 @@ using PcapDotNet.Packets.Ethernet;
namespace
PcapDotNet.Core.Extensions
{
/// <summary>
/// Extension methods for LivePacketDevice class.
/// </summary>
public
static
class
LivePacketDeviceExtensions
{
public
static
NetworkInterface
GetNetworkInterface
(
this
LivePacketDevice
livePacketDevice
)
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
View file @
87c38e83
using
System
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Arp
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
...
...
@@ -76,7 +77,7 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
EthernetType
.
Arp
,
packet
.
Ethernet
.
EtherType
,
"Ethernet EtherType"
);
// Arp
Assert
.
AreEqual
(
ArpDatagram
.
HeaderBaseLength
+
2
*
arpLayer
.
SenderHardwareAddress
.
Count
+
2
*
arpLayer
.
SenderProtocolAddress
.
Count
,
packet
.
Ethernet
.
Arp
.
Length
,
"Arp length"
);
Assert
.
AreEqual
(
ArpDatagram
.
HeaderBaseLength
+
2
*
arpLayer
.
SenderHardwareAddress
.
Count
+
2
*
arpLayer
.
SenderProtocolAddress
.
Count
,
packet
.
Ethernet
.
Arp
.
Length
,
"Arp length"
);
Assert
.
AreEqual
(
ArpHardwareType
.
Ethernet
,
packet
.
Ethernet
.
Arp
.
HardwareType
,
"Arp hardware type"
);
Assert
.
AreEqual
(
arpLayer
,
packet
.
Ethernet
.
Arp
.
ExtractLayer
(),
"ARP Layer"
);
}
...
...
@@ -91,13 +92,9 @@ namespace PcapDotNet.Packets.Test
Source
=
new
MacAddress
(),
EtherType
=
EthernetType
.
QInQ
},
new
ArpLayer
new
ArpLayer
(
new
byte
[
8
],
new
byte
[]
{
1
,
2
,
3
,
4
},
new
byte
[
8
],
new
byte
[]
{
11
,
22
,
33
,
44
})
{
Operation
=
ArpOperation
.
Request
,
SenderHardwareAddress
=
new
byte
[
8
],
SenderProtocolAddress
=
new
byte
[]{
1
,
2
,
3
,
4
},
TargetHardwareAddress
=
new
byte
[
8
],
TargetProtocolAddress
=
new
byte
[]{
11
,
22
,
33
,
44
}
});
Assert
.
AreEqual
(
new
IpV4Address
(
"1.2.3.4"
),
packet
.
Ethernet
.
Arp
.
SenderProtocolIpV4Address
);
...
...
@@ -114,13 +111,9 @@ namespace PcapDotNet.Packets.Test
Source
=
new
MacAddress
(),
EtherType
=
EthernetType
.
IpV4
},
new
ArpLayer
new
ArpLayer
(
new
byte
[
4
],
new
byte
[
6
],
new
byte
[
5
],
new
byte
[
6
])
{
Operation
=
ArpOperation
.
Request
,
SenderHardwareAddress
=
new
byte
[
4
],
SenderProtocolAddress
=
new
byte
[
6
],
TargetHardwareAddress
=
new
byte
[
5
],
TargetProtocolAddress
=
new
byte
[
6
]
});
Assert
.
IsNull
(
packet
);
Assert
.
Fail
();
...
...
@@ -136,13 +129,9 @@ namespace PcapDotNet.Packets.Test
Source
=
new
MacAddress
(),
EtherType
=
EthernetType
.
IpV4
},
new
ArpLayer
new
ArpLayer
(
new
byte
[
4
],
new
byte
[
6
],
new
byte
[
4
],
new
byte
[
7
])
{
Operation
=
ArpOperation
.
Request
,
SenderHardwareAddress
=
new
byte
[
4
],
SenderProtocolAddress
=
new
byte
[
6
],
TargetHardwareAddress
=
new
byte
[
4
],
TargetProtocolAddress
=
new
byte
[
7
]
});
Assert
.
IsNull
(
packet
);
Assert
.
Fail
();
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IgmpTests.cs
View file @
87c38e83
...
...
@@ -260,15 +260,14 @@ namespace PcapDotNet.Packets.Test
// non zero max response code report version 3
Packet
reportVersion3
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
IgmpReportVersion3Layer
{
GroupRecords
=
new
[]
{
new
IgmpGroupRecord
(
IgmpRecordType
.
CurrentStateRecordModeIsExclude
,
IpV4Address
.
Zero
,
new
List
<
IpV4Address
>(),
Datagram
.
Empty
)
}
});
new
IgmpReportVersion3Layer
(
new
[]
{
new
IgmpGroupRecord
(
IgmpRecordType
.
CurrentStateRecordModeIsExclude
,
IpV4Address
.
Zero
,
new
List
<
IpV4Address
>(),
Datagram
.
Empty
)
}
));
buffer
=
new
byte
[
reportVersion3
.
Length
];
reportVersion3
.
Buffer
.
BlockCopy
(
0
,
buffer
,
0
,
buffer
.
Length
);
...
...
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
View file @
87c38e83
...
...
@@ -106,14 +106,11 @@ namespace PcapDotNet.Packets.TestUtils
{
byte
hardwareAddressLength
=
random
.
NextByte
();
byte
protocolAddressLength
=
random
.
NextByte
();
return
new
ArpLayer
return
new
ArpLayer
(
random
.
NextBytes
(
hardwareAddressLength
).
AsReadOnly
(),
random
.
NextBytes
(
protocolAddressLength
).
AsReadOnly
(),
random
.
NextBytes
(
hardwareAddressLength
).
AsReadOnly
(),
random
.
NextBytes
(
protocolAddressLength
).
AsReadOnly
())
{
ProtocolType
=
random
.
NextEnum
<
EthernetType
>(),
Operation
=
random
.
NextEnum
<
ArpOperation
>(),
SenderHardwareAddress
=
random
.
NextBytes
(
hardwareAddressLength
),
SenderProtocolAddress
=
random
.
NextBytes
(
protocolAddressLength
),
TargetHardwareAddress
=
random
.
NextBytes
(
hardwareAddressLength
),
TargetProtocolAddress
=
random
.
NextBytes
(
protocolAddressLength
)
};
}
...
...
@@ -525,14 +522,13 @@ namespace PcapDotNet.Packets.TestUtils
IgmpDatagram
.
MaxVersion3MaxResponseTime
-
TimeSpan
.
FromTicks
(
1
));
igmpQueryInterval
=
random
.
NextTimeSpan
(
TimeSpan
.
Zero
,
IgmpDatagram
.
MaxQueryInterval
-
TimeSpan
.
FromTicks
(
1
));
igmpSourceAddresses
=
random
.
NextIpV4Addresses
(
random
.
Next
(
1000
));
return
new
IgmpQueryVersion3Layer
return
new
IgmpQueryVersion3Layer
(
igmpSourceAddresses
)
{
MaxResponseTime
=
igmpMaxResponseTime
,
GroupAddress
=
igmpGroupAddress
,
IsSuppressRouterSideProcessing
=
igmpIsSuppressRouterSideProcessing
.
Value
,
QueryRobustnessVariable
=
igmpQueryRobustnessVariable
.
Value
,
QueryInterval
=
igmpQueryInterval
.
Value
,
SourceAddresses
=
igmpSourceAddresses
};
default
:
...
...
@@ -561,10 +557,7 @@ namespace PcapDotNet.Packets.TestUtils
case
IgmpMessageType
.
MembershipReportVersion3
:
igmpGroupRecords
=
random
.
NextIgmpGroupRecords
(
random
.
Next
(
100
));
return
new
IgmpReportVersion3Layer
{
GroupRecords
=
igmpGroupRecords
};
return
new
IgmpReportVersion3Layer
(
igmpGroupRecords
);
default
:
throw
new
InvalidOperationException
(
"Invalid message type "
+
igmpMessageType
);
...
...
@@ -673,11 +666,10 @@ namespace PcapDotNet.Packets.TestUtils
case
IcmpMessageType
.
RouterAdvertisement
:
return
new
IcmpRouterAdvertisementLayer
return
new
IcmpRouterAdvertisementLayer
(
random
.
NextIcmpRouterAdvertisementEntries
(
random
.
Next
(
10
)).
ToList
())
{
Checksum
=
checksum
,
Lifetime
=
random
.
NextTimeSpan
(
TimeSpan
.
Zero
,
TimeSpan
.
FromSeconds
(
ushort
.
MaxValue
)),
Entries
=
random
.
NextIcmpRouterAdvertisementEntries
(
random
.
Next
(
10
)).
ToList
()
};
case
IcmpMessageType
.
RouterSolicitation
:
...
...
PcapDotNet/src/PcapDotNet.Packets/Arp/ArpDatagram.cs
View file @
87c38e83
...
...
@@ -2,6 +2,7 @@ using System;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Linq
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
...
...
@@ -104,7 +105,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary>
public
ReadOnlyCollection
<
byte
>
SenderHardwareAddress
{
get
{
return
new
ReadOnlyCollection
<
byte
>(
ReadBytes
(
Offset
.
SenderHardwareAddress
,
HardwareLength
)
);
}
get
{
return
ReadBytes
(
Offset
.
SenderHardwareAddress
,
HardwareLength
).
AsReadOnly
(
);
}
}
/// <summary>
...
...
@@ -112,7 +113,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary>
public
ReadOnlyCollection
<
byte
>
SenderProtocolAddress
{
get
{
return
new
ReadOnlyCollection
<
byte
>(
ReadBytes
(
OffsetSenderProtocolAddress
,
ProtocolLength
)
);
}
get
{
return
ReadBytes
(
OffsetSenderProtocolAddress
,
ProtocolLength
).
AsReadOnly
(
);
}
}
/// <summary>
...
...
@@ -129,7 +130,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary>
public
ReadOnlyCollection
<
byte
>
TargetHardwareAddress
{
get
{
return
new
ReadOnlyCollection
<
byte
>(
ReadBytes
(
OffsetTargetHardwareAddress
,
HardwareLength
)
);
}
get
{
return
ReadBytes
(
OffsetTargetHardwareAddress
,
HardwareLength
).
AsReadOnly
(
);
}
}
/// <summary>
...
...
@@ -137,7 +138,7 @@ namespace PcapDotNet.Packets.Arp
/// </summary>
public
ReadOnlyCollection
<
byte
>
TargetProtocolAddress
{
get
{
return
new
ReadOnlyCollection
<
byte
>(
ReadBytes
(
OffsetTargetProtocolAddress
,
ProtocolLength
)
);
}
get
{
return
ReadBytes
(
OffsetTargetProtocolAddress
,
ProtocolLength
).
AsReadOnly
(
);
}
}
/// <summary>
...
...
@@ -148,16 +149,15 @@ namespace PcapDotNet.Packets.Arp
get
{
return
ReadIpV4Address
(
OffsetTargetProtocolAddress
,
Endianity
.
Big
);
}
}
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
public
override
ILayer
ExtractLayer
()
{
return
new
ArpLayer
return
new
ArpLayer
(
SenderHardwareAddress
,
SenderProtocolAddress
,
TargetHardwareAddress
,
TargetProtocolAddress
)
{
ProtocolType
=
ProtocolType
,
Operation
=
Operation
,
SenderHardwareAddress
=
SenderHardwareAddress
,
SenderProtocolAddress
=
SenderProtocolAddress
,
TargetHardwareAddress
=
TargetHardwareAddress
,
TargetProtocolAddress
=
TargetProtocolAddress
};
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Arp/ArpLayer.cs
View file @
87c38e83
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Linq
;
using
System.Xml.Serialization
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Ethernet
;
namespace
PcapDotNet.Packets.Arp
{
/// <summary>
/// Represents an ARP protocol layer.
/// </summary>
public
class
ArpLayer
:
Layer
,
IEthernetNextLayer
{
/// <summary>
/// Create an ARP layer by giving the different addresses.
/// </summary>
/// <param name="senderHardwareAddress">Hardware address of the sender.</param>
/// <param name="senderProtocolAddress">Protocol address of the sender.</param>
/// <param name="targetHardwareAddress">Hardware address of the intended receiver. This field is ignored in requests.</param>
/// <param name="targetProtocolAddress">Protocol address of the intended receiver.</param>
public
ArpLayer
(
IList
<
byte
>
senderHardwareAddress
,
IList
<
byte
>
senderProtocolAddress
,
IList
<
byte
>
targetHardwareAddress
,
IList
<
byte
>
targetProtocolAddress
)
{
_senderHardwareAddress
=
senderHardwareAddress
;
_senderProtocolAddress
=
senderProtocolAddress
;
_targetHardwareAddress
=
targetHardwareAddress
;
_targetProtocolAddress
=
targetProtocolAddress
;
}
/// <summary>
/// Each protocol is assigned a number used in this field.
/// </summary>
public
EthernetType
ProtocolType
{
get
;
set
;
}
/// <summary>
/// Specifies the operation the sender is performing.
/// </summary>
public
ArpOperation
Operation
{
get
;
set
;
}
public
IList
<
byte
>
SenderHardwareAddress
{
get
;
set
;
}
public
IList
<
byte
>
SenderProtocolAddress
{
get
;
set
;
}
public
IList
<
byte
>
TargetHardwareAddress
{
get
;
set
;
}
public
IList
<
byte
>
TargetProtocolAddress
{
get
;
set
;
}
/// <summary>
/// Hardware address of the sender.
/// </summary>
public
IList
<
byte
>
SenderHardwareAddress
{
get
{
return
_senderHardwareAddress
;
}
}
/// <summary>
/// Protocol address of the sender.
/// </summary>
public
IList
<
byte
>
SenderProtocolAddress
{
get
{
return
_senderProtocolAddress
;
}
}
/// <summary>
/// Hardware address of the intended receiver.
/// This field is ignored in requests.
/// </summary>
public
IList
<
byte
>
TargetHardwareAddress
{
get
{
return
_targetHardwareAddress
;
}
}
/// <summary>
/// Protocol address of the intended receiver.
/// </summary>
public
IList
<
byte
>
TargetProtocolAddress
{
get
{
return
_targetProtocolAddress
;
}
}
/// <summary>
/// The Ethernet Type the Ethernet layer should write when this layer is the Ethernet payload.
/// </summary>
public
EthernetType
PreviousLayerEtherType
{
get
{
return
EthernetType
.
Arp
;
}
}
/// <summary>
/// The default MAC Address value when this layer is the Ethernet payload.
/// null means there is no default value.
/// </summary>
public
MacAddress
?
PreviousLayerDefaultDestination
{
get
{
return
EthernetDatagram
.
BroadcastAddress
;
}
}
/// <summary>
/// The number of bytes this layer will take.
/// </summary>
public
override
int
Length
{
get
{
return
ArpDatagram
.
GetHeaderLength
(
SenderHardwareAddress
.
Count
,
SenderProtocolAddress
.
Count
);
}
}
/// <summary>
/// Writes the layer to the buffer.
/// </summary>
/// <param name="buffer">The buffer to write the layer to.</param>
/// <param name="offset">The offset in the buffer to start writing the layer at.</param>
/// <param name="payloadLength">The length of the layer's payload (the number of bytes after the layer in the packet).</param>
/// <param name="previousLayer">The layer that comes before this layer. null if this is the first layer.</param>
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
public
override
void
Write
(
byte
[]
buffer
,
int
offset
,
int
payloadLength
,
ILayer
previousLayer
,
ILayer
nextLayer
)
{
if
(
previousLayer
==
null
)
...
...
@@ -59,6 +117,11 @@ namespace PcapDotNet.Packets.Arp
SenderHardwareAddress
,
SenderProtocolAddress
,
TargetHardwareAddress
,
TargetProtocolAddress
);
}
/// <summary>
/// True iff the two ARP layers have equal protocol type, operation and addresses.
/// </summary>
/// <param name="other">The ARP layer to compare the layer to.</param>
/// <returns>True iff the two layers are equal.</returns>
public
bool
Equals
(
ArpLayer
other
)
{
return
other
!=
null
&&
...
...
@@ -80,5 +143,10 @@ namespace PcapDotNet.Packets.Arp
(((
ushort
)
ProtocolType
<<
16
)
+
(
ushort
)
Operation
);
}
private
readonly
IList
<
byte
>
_senderHardwareAddress
;
private
readonly
IList
<
byte
>
_senderProtocolAddress
;
private
readonly
IList
<
byte
>
_targetHardwareAddress
;
private
readonly
IList
<
byte
>
_targetProtocolAddress
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Arp/IArpPreviousLayer.cs
View file @
87c38e83
...
...
@@ -6,6 +6,9 @@ namespace PcapDotNet.Packets.Arp
/// </summary>
public
interface
IArpPreviousLayer
:
ILayer
{
ArpHardwareType
PreviousLayerHardwareType
{
get
;
}
/// <summary>
/// The ARP Hardware Type of the layer before the ARP layer.
/// </summary>
ArpHardwareType
PreviousLayerHardwareType
{
get
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Datagram.cs
View file @
87c38e83
...
...
@@ -76,6 +76,9 @@ namespace PcapDotNet.Packets
}
}
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
public
virtual
ILayer
ExtractLayer
()
{
return
new
PayloadLayer
...
...
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetDatagram.cs
View file @
87c38e83
...
...
@@ -93,6 +93,9 @@ namespace PcapDotNet.Packets.Ethernet
}
}
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
public
override
ILayer
ExtractLayer
()
{
return
new
EthernetLayer
()
...
...
PcapDotNet/src/PcapDotNet.Packets/Ethernet/IEthernetNextLayer.cs
View file @
87c38e83
...
...
@@ -6,7 +6,15 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary>
public
interface
IEthernetNextLayer
:
ILayer
{
/// <summary>
/// The Ethernet Type the Ethernet layer should write when this layer is the Ethernet payload.
/// </summary>
EthernetType
PreviousLayerEtherType
{
get
;
}
/// <summary>
/// The default MAC Address value when this layer is the Ethernet payload.
/// null means there is no default value.
/// </summary>
MacAddress
?
PreviousLayerDefaultDestination
{
get
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Ethernet/MacAddress.cs
View file @
87c38e83
...
...
@@ -110,7 +110,7 @@ namespace PcapDotNet.Packets.Ethernet
(
byte
)(
_value
));
}
private
static
readonly
MacAddress
_zero
;
private
static
readonly
MacAddress
_zero
=
new
MacAddress
(
0
)
;
private
readonly
UInt48
_value
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/ILayer.cs
View file @
87c38e83
...
...
@@ -9,9 +9,35 @@ namespace PcapDotNet.Packets
/// </summary>
public
interface
ILayer
{
/// <summary>
/// The number of bytes this layer will take.
/// </summary>
int
Length
{
get
;
}
/// <summary>
/// Writes the layer to the buffer.
/// </summary>
/// <param name="buffer">The buffer to write the layer to.</param>
/// <param name="offset">The offset in the buffer to start writing the layer at.</param>
/// <param name="payloadLength">The length of the layer's payload (the number of bytes after the layer in the packet).</param>
/// <param name="previousLayer">The layer that comes before this layer. null if this is the first layer.</param>
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
void
Write
(
byte
[]
buffer
,
int
offset
,
int
payloadLength
,
ILayer
previousLayer
,
ILayer
nextLayer
);
/// <summary>
/// Finalizes the layer data in the buffer.
/// Used for fields that must be calculated according to the layer's payload (like checksum).
/// </summary>
/// <param name="buffer">The buffer to finalize the layer in.</param>
/// <param name="offset">The offset in the buffer the layer starts.</param>
/// <param name="payloadLength">The length of the layer's payload (the number of bytes after the layer in the packet).</param>
/// <param name="nextLayer">The layer that comes after this layer. null if this is the last layer.</param>
void
Finalize
(
byte
[]
buffer
,
int
offset
,
int
payloadLength
,
ILayer
nextLayer
);
/// <summary>
/// The kind of the data link of the layer.
/// Can be null if this is not the first layer in the packet.
/// </summary>
DataLinkKind
?
DataLink
{
get
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpDatagram.cs
View file @
87c38e83
...
...
@@ -81,7 +81,7 @@ namespace PcapDotNet.Packets.Icmp
}
}
public
abstract
ILayer
ExtractLayer
();
public
override
abstract
ILayer
ExtractLayer
();
public
Datagram
Payload
{
...
...
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpRouterAdvertisementDatagram.cs
View file @
87c38e83
...
...
@@ -101,11 +101,10 @@ namespace PcapDotNet.Packets.Icmp
public
override
ILayer
ExtractLayer
()
{
return
new
IcmpRouterAdvertisementLayer
return
new
IcmpRouterAdvertisementLayer
(
Entries
.
ToList
())
{
Checksum
=
Checksum
,
Lifetime
=
Lifetime
,
Entries
=
Entries
.
ToList
()
};
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Icmp/IcmpRouterAdvertisementLayer.cs
View file @
87c38e83
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Linq
;
namespace
PcapDotNet.Packets.Icmp
{
public
class
IcmpRouterAdvertisementLayer
:
IcmpLayer
{
public
IcmpRouterAdvertisementLayer
(
IList
<
IcmpRouterAdvertisementEntry
>
entries
)
{
_entries
=
entries
;
}
public
TimeSpan
Lifetime
{
get
;
set
;
}
public
List
<
IcmpRouterAdvertisementEntry
>
Entries
{
get
;
set
;
}
public
IList
<
IcmpRouterAdvertisementEntry
>
Entries
{
get
{
return
_entries
;}
}
public
override
IcmpMessageType
MessageType
{
...
...
@@ -47,5 +53,7 @@ namespace PcapDotNet.Packets.Icmp
{
return
base
.
Equals
(
other
)
&&
Equals
(
other
as
IcmpRouterAdvertisementLayer
);
}
private
readonly
IList
<
IcmpRouterAdvertisementEntry
>
_entries
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpDatagram.cs
View file @
87c38e83
...
...
@@ -505,14 +505,13 @@ namespace PcapDotNet.Packets.Igmp
};
case
IgmpQueryVersion
.
Version3
:
return
new
IgmpQueryVersion3Layer
return
new
IgmpQueryVersion3Layer
(
SourceAddresses
)
{
MaxResponseTime
=
MaxResponseTime
,
GroupAddress
=
GroupAddress
,
IsSuppressRouterSideProcessing
=
IsSuppressRouterSideProcessing
,
QueryRobustnessVariable
=
QueryRobustnessVariable
,
QueryInterval
=
QueryInterval
,
SourceAddresses
=
SourceAddresses
};
default
:
...
...
@@ -540,10 +539,7 @@ namespace PcapDotNet.Packets.Igmp
};
case
IgmpMessageType
.
MembershipReportVersion3
:
return
new
IgmpReportVersion3Layer
{
GroupRecords
=
GroupRecords
.
Select
(
record
=>
record
.
ToGroupRecord
()).
ToList
()
};
return
new
IgmpReportVersion3Layer
(
GroupRecords
.
Select
(
record
=>
record
.
ToGroupRecord
()).
ToList
());
default
:
throw
new
InvalidOperationException
(
"Invalid message type "
+
MessageType
);
...
...
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpQueryVersion3Layer.cs
View file @
87c38e83
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Linq
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.IpV4
;
...
...
@@ -9,8 +10,13 @@ namespace PcapDotNet.Packets.Igmp
public
class
IgmpQueryVersion3Layer
:
IgmpLayer
,
IIgmpLayerWithGroupAddress
{
public
IgmpQueryVersion3Layer
()
:
this
(
new
List
<
IpV4Address
>())
{
SourceAddresses
=
new
List
<
IpV4Address
>();
}
public
IgmpQueryVersion3Layer
(
IList
<
IpV4Address
>
sourceAddresses
)
{
_sourceAddresses
=
sourceAddresses
;
}
public
TimeSpan
MaxResponseTime
{
get
;
set
;
}
...
...
@@ -21,7 +27,7 @@ namespace PcapDotNet.Packets.Igmp
public
TimeSpan
QueryInterval
{
get
;
set
;}
public
IList
<
IpV4Address
>
SourceAddresses
{
get
;
set
;
}
public
IList
<
IpV4Address
>
SourceAddresses
{
get
{
return
_sourceAddresses
;}
}
public
override
int
Length
{
...
...
@@ -76,5 +82,7 @@ namespace PcapDotNet.Packets.Igmp
SourceAddresses
.
SequenceGetHashCode
();
}
private
readonly
IList
<
IpV4Address
>
_sourceAddresses
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Igmp/IgmpReportVersion3Layer.cs
View file @
87c38e83
using
System
;
using
System.Collections.Generic
;
using
System.Collections.ObjectModel
;
using
System.Linq
;
using
PcapDotNet.Base
;
...
...
@@ -7,7 +8,20 @@ namespace PcapDotNet.Packets.Igmp
{
public
class
IgmpReportVersion3Layer
:
IgmpLayer
{
public
IList
<
IgmpGroupRecord
>
GroupRecords
{
get
;
set
;}
public
IgmpReportVersion3Layer
()
:
this
(
new
List
<
IgmpGroupRecord
>())
{
}
public
IgmpReportVersion3Layer
(
IList
<
IgmpGroupRecord
>
groupRecords
)
{
_groupRecords
=
groupRecords
;
}
public
IList
<
IgmpGroupRecord
>
GroupRecords
{
get
{
return
_groupRecords
;
}
}
public
override
int
Length
{
...
...
@@ -45,5 +59,7 @@ namespace PcapDotNet.Packets.Igmp
return
base
.
GetHashCode
()
^
GroupRecords
.
SequenceGetHashCode
();
}
private
readonly
IList
<
IgmpGroupRecord
>
_groupRecords
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/IpV6/IpV6Address.cs
View file @
87c38e83
...
...
@@ -54,11 +54,11 @@ namespace PcapDotNet.Packets.IpV6
{
uint
lastPartValue
=
new
IpV4Address
(
lastPart
).
ToValue
();
cannonizedValue
=
cannonizedValue
.
Substring
(
0
,
lastColonIndex
+
1
)
+
(
lastPartValue
>>
16
).
ToString
(
"x"
,
CultureInfo
.
InvariantCulture
)
+
":"
+
(
lastPartValue
&
0x0000FFFF
).
ToString
(
"x"
);
(
lastPartValue
>>
16
).
ToString
(
"x"
,
CultureInfo
.
InvariantCulture
)
+
":"
+
(
lastPartValue
&
0x0000FFFF
).
ToString
(
"x"
,
CultureInfo
.
InvariantCulture
);
}
// Handle ...::...
int
doubleColonIndex
=
cannonizedValue
.
IndexOf
(
"::"
,
StringComparison
.
InvariantCulture
);
int
doubleColonIndex
=
cannonizedValue
.
IndexOf
(
"::"
,
StringComparison
.
Ordinal
);
if
(
doubleColonIndex
!=
-
1
)
{
int
numMissingColons
=
7
-
cannonizedValue
.
Count
(
':'
);
...
...
PcapDotNet/src/PcapDotNet.Packets/Layer.cs
View file @
87c38e83
...
...
@@ -10,6 +10,7 @@ namespace PcapDotNet.Packets
public
abstract
class
Layer
:
ILayer
{
public
abstract
int
Length
{
get
;
}
public
abstract
void
Write
(
byte
[]
buffer
,
int
offset
,
int
payloadLength
,
ILayer
previousLayer
,
ILayer
nextLayer
);
public
virtual
void
Finalize
(
byte
[]
buffer
,
int
offset
,
int
payloadLength
,
ILayer
nextLayer
)
{
...
...
@@ -20,17 +21,29 @@ namespace PcapDotNet.Packets
get
{
return
null
;
}
}
/// <summary>
/// True iff the two objects are equal Layers.
/// In order to be equal, the two layers must have identical length and data link.
/// </summary>
public
virtual
bool
Equals
(
Layer
other
)
{
return
other
!=
null
&&
Length
==
other
.
Length
&&
DataLink
==
other
.
DataLink
;
}
/// <summary>
/// True iff the two objects are equal Layers.
/// In order to be equal, the two layers must have identical length and data link.
/// </summary>
public
override
sealed
bool
Equals
(
object
obj
)
{
return
Equals
(
obj
as
Layer
);
}
/// <summary>
/// Returns a hash code for the layer.
/// The hash code base is a XOR of the layer length and data link.
/// </summary>
public
override
int
GetHashCode
()
{
return
Length
.
GetHashCode
()
^
DataLink
.
GetHashCode
();
...
...
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
87c38e83
...
...
@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.
30729
</ProductVersion>
<ProductVersion>
9.0.
21022
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{8A184AF5-E46C-482C-81A3-76D8CE290104}
</ProjectGuid>
<OutputType>
Library
</OutputType>
...
...
@@ -30,7 +30,7 @@
<WarningLevel>
4
</WarningLevel>
<AllowUnsafeBlocks>
true
</AllowUnsafeBlocks>
<RunCodeAnalysis>
true
</RunCodeAnalysis>
<CodeAnalysisRules>
-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Naming#CA1710
</CodeAnalysisRules>
<CodeAnalysisRules>
-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.
Maintainability#CA1501;-Microsoft.
Naming#CA1710
</CodeAnalysisRules>
<DocumentationFile>
..\..\bin\Debug\PcapDotNet.Packets.XML
</DocumentationFile>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
...
...
@@ -42,7 +42,7 @@
<WarningLevel>
4
</WarningLevel>
<AllowUnsafeBlocks>
true
</AllowUnsafeBlocks>
<RunCodeAnalysis>
true
</RunCodeAnalysis>
<CodeAnalysisRules>
-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Naming#CA1710
</CodeAnalysisRules>
<CodeAnalysisRules>
-Microsoft.Design#CA1021;-Microsoft.Design#CA1045;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.
Maintainability#CA1501;-Microsoft.
Naming#CA1710
</CodeAnalysisRules>
<DocumentationFile>
..\..\bin\Release\PcapDotNet.Packets.XML
</DocumentationFile>
</PropertyGroup>
<ItemGroup>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment