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
b2293f3d
Commit
b2293f3d
authored
Nov 28, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ICMP
parent
1e1408a0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
153 additions
and
77 deletions
+153
-77
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+1
-7
IpV4Tests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
+101
-35
RandomPacketsExtensions.cs
...c/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
+11
-6
IpV4Datagram.cs
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
+5
-2
PacketBuilder.cs
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder.cs
+26
-26
PacketBuilder2.cs
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder2.cs
+9
-1
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
b2293f3d
...
...
@@ -224,13 +224,7 @@ namespace PcapDotNet.Core.Test
random
.
NextBytes
(
hardwareAddressLength
),
random
.
NextBytes
(
protocolAddressLength
));
case
PacketType
.
IpV4
:
return
PacketBuilder
.
EthernetIpV4
(
packetTimestamp
,
random
.
NextMacAddress
(),
random
.
NextMacAddress
(),
random
.
NextByte
(),
random
.
NextUShort
(),
random
.
NextIpV4Fragmentation
(),
random
.
NextByte
(),
random
.
NextEnum
<
IpV4Protocol
>(),
random
.
NextIpV4Address
(),
random
.
NextIpV4Address
(),
random
.
NextIpV4Options
(),
random
.
NextDatagram
(
random
.
Next
(
100
)));
return
PacketBuilder2
.
Build
(
packetTimestamp
,
random
.
NextEthernetLayer
(
EthernetType
.
None
),
random
.
NextIpV4Layer
(),
random
.
NextPayloadLayer
(
random
.
Next
(
100
)));
case
PacketType
.
Igmp
:
return
CreateRandomIgmpPacket
(
packetTimestamp
,
random
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
View file @
b2293f3d
This diff is collapsed.
Click to expand it.
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
View file @
b2293f3d
...
...
@@ -45,14 +45,19 @@ namespace PcapDotNet.Packets.TestUtils
// Ethernet
public
static
EthernetLayer
NextEthernetLayer
(
this
Random
random
)
public
static
EthernetLayer
NextEthernetLayer
(
this
Random
random
,
EthernetType
etherType
)
{
return
new
EthernetLayer
{
Source
=
random
.
NextMacAddress
(),
Destination
=
random
.
NextMacAddress
(),
EtherType
=
random
.
NextEnum
(
EthernetType
.
None
)
};
{
Source
=
random
.
NextMacAddress
(),
Destination
=
random
.
NextMacAddress
(),
EtherType
=
etherType
};
}
public
static
EthernetLayer
NextEthernetLayer
(
this
Random
random
)
{
return
random
.
NextEthernetLayer
(
random
.
NextEnum
(
EthernetType
.
None
));
}
public
static
MacAddress
NextMacAddress
(
this
Random
random
)
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
View file @
b2293f3d
...
...
@@ -215,6 +215,7 @@ namespace PcapDotNet.Packets.IpV4
Fragmentation
=
Fragmentation
,
Ttl
=
Ttl
,
Protocol
=
Protocol
,
HeaderChecksum
=
HeaderChecksum
,
Source
=
Source
,
Destination
=
Destination
,
Options
=
Options
,
...
...
@@ -312,7 +313,7 @@ namespace PcapDotNet.Packets.IpV4
internal
static
void
WriteHeader
(
byte
[]
buffer
,
int
offset
,
byte
typeOfService
,
ushort
identification
,
IpV4Fragmentation
fragmentation
,
byte
ttl
,
IpV4Protocol
protocol
,
byte
ttl
,
IpV4Protocol
protocol
,
ushort
?
checksum
,
IpV4Address
source
,
IpV4Address
destination
,
IpV4Options
options
,
int
payloadLength
)
{
...
...
@@ -330,7 +331,9 @@ namespace PcapDotNet.Packets.IpV4
buffer
.
Write
(
offset
+
Offset
.
Destination
,
destination
,
Endianity
.
Big
);
options
.
Write
(
buffer
,
offset
+
Offset
.
Options
);
buffer
.
Write
(
offset
+
Offset
.
HeaderChecksum
,
Sum16BitsToChecksum
(
Sum16Bits
(
buffer
,
offset
,
headerLength
)),
Endianity
.
Big
);
if
(
checksum
==
null
)
checksum
=
Sum16BitsToChecksum
(
Sum16Bits
(
buffer
,
offset
,
headerLength
));
buffer
.
Write
(
offset
+
Offset
.
HeaderChecksum
,
checksum
.
Value
,
Endianity
.
Big
);
}
internal
static
void
WriteTransportChecksum
(
byte
[]
buffer
,
int
offset
,
int
headerLength
,
ushort
transportLength
,
int
transportChecksumOffset
,
bool
isChecksumOptional
)
...
...
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder.cs
View file @
b2293f3d
...
...
@@ -90,25 +90,25 @@ namespace PcapDotNet.Packets
/// <param name="ipV4Options">The IPv4 options.</param>
/// <param name="ipV4Payload">The IPv4 payload.</param>
/// <returns>A packet with an IPv4 over Ethernet datagram.</returns>
public
static
Packet
EthernetIpV4
(
DateTime
timestamp
,
MacAddress
ethernetSource
,
MacAddress
ethernetDestination
,
byte
ipV4TypeOfService
,
ushort
ipV4Identification
,
IpV4Fragmentation
ipV4Fragmentation
,
byte
ipV4Ttl
,
IpV4Protocol
ipV4Protocol
,
IpV4Address
ipV4SourceAddress
,
IpV4Address
ipV4DestinationAddress
,
IpV4Options
ipV4Options
,
Datagram
ipV4Payload
)
{
int
ipHeaderLength
=
IpV4Datagram
.
HeaderMinimumLength
+
ipV4Options
.
BytesLength
;
byte
[]
buffer
=
new
byte
[
EthernetDatagram
.
HeaderLength
+
ipHeaderLength
+
ipV4Payload
.
Length
];
EthernetDatagram
.
WriteHeader
(
buffer
,
0
,
ethernetSource
,
ethernetDestination
,
EthernetType
.
IpV4
);
IpV4Datagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4Protocol
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
ipV4Payload
.
Length
);
ipV4Payload
.
Write
(
buffer
,
EthernetDatagram
.
HeaderLength
+
ipHeaderLength
);
return
new
Packet
(
buffer
,
timestamp
,
DataLinkKind
.
Ethernet
);
}
//
public static Packet EthernetIpV4(DateTime timestamp,
//
MacAddress ethernetSource, MacAddress ethernetDestination,
//
byte ipV4TypeOfService, ushort ipV4Identification, IpV4Fragmentation ipV4Fragmentation,
//
byte ipV4Ttl, IpV4Protocol ipV4Protocol,
//
IpV4Address ipV4SourceAddress, IpV4Address ipV4DestinationAddress,
//
IpV4Options ipV4Options,
//
Datagram ipV4Payload)
//
{
//
int ipHeaderLength = IpV4Datagram.HeaderMinimumLength + ipV4Options.BytesLength;
//
byte[] buffer = new byte[EthernetDatagram.HeaderLength + ipHeaderLength + ipV4Payload.Length];
//
EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4);
//
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
//
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
//
ipV4Ttl, ipV4Protocol,
//
ipV4SourceAddress, ipV4DestinationAddress,
//
ipV4Options, ipV4Payload.Length);
//
ipV4Payload.Write(buffer, EthernetDatagram.HeaderLength + ipHeaderLength);
//
return new Packet(buffer, timestamp, DataLinkKind.Ethernet);
//
}
/// <summary>
/// Builds an ICMP over IPv4 over Ethernet packet.
...
...
@@ -244,14 +244,14 @@ namespace PcapDotNet.Packets
EthernetDatagram
.
WriteHeader
(
buffer
,
0
,
ethernetSource
,
ethernetDestination
,
EthernetType
.
IpV4
);
IpV4Datagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
IpV4Protocol
.
InternetControlMessageProtocol
,
ipV4Ttl
,
IpV4Protocol
.
InternetControlMessageProtocol
,
null
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
ipPayloadLength
);
IcmpDatagram
.
WriteHeader
(
buffer
,
icmpOffset
,
IcmpMessageType
.
DestinationUnreachable
,
icmpCode
,
icmpValueAccordingToType
);
IpV4Datagram
.
WriteHeader
(
buffer
,
icmpOffset
+
IcmpDatagram
.
HeaderLength
,
icmpIpV4TypeOfService
,
icmpIpV4Identification
,
icmpIpV4Fragmentation
,
icmpIpV4Ttl
,
icmpIpV4Protocol
,
icmpIpV4Ttl
,
icmpIpV4Protocol
,
null
,
icmpIpV4SourceAddress
,
icmpIpV4DestinationAddress
,
icmpIpV4Options
,
icmpIpV4Payload
.
Length
);
icmpIpV4Payload
.
Write
(
buffer
,
icmpOffset
+
IcmpDatagram
.
HeaderLength
+
icmpIpHeaderLength
);
...
...
@@ -498,7 +498,7 @@ namespace PcapDotNet.Packets
EthernetDatagram
.
WriteHeader
(
buffer
,
0
,
ethernetSource
,
ethernetDestination
,
EthernetType
.
IpV4
);
IpV4Datagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
IpV4Protocol
.
InternetGroupManagementProtocol
,
ipV4Ttl
,
IpV4Protocol
.
InternetGroupManagementProtocol
,
null
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
igmpLength
);
IgmpDatagram
.
WriteQueryVersion3
(
buffer
,
EthernetDatagram
.
HeaderLength
+
ipHeaderLength
,
...
...
@@ -536,7 +536,7 @@ namespace PcapDotNet.Packets
EthernetDatagram
.
WriteHeader
(
buffer
,
0
,
ethernetSource
,
ethernetDestination
,
EthernetType
.
IpV4
);
IpV4Datagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
IpV4Protocol
.
InternetGroupManagementProtocol
,
ipV4Ttl
,
IpV4Protocol
.
InternetGroupManagementProtocol
,
null
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
igmpLength
);
IgmpDatagram
.
WriteReportVersion3
(
buffer
,
EthernetDatagram
.
HeaderLength
+
ipHeaderLength
,
...
...
@@ -557,7 +557,7 @@ namespace PcapDotNet.Packets
EthernetDatagram
.
WriteHeader
(
buffer
,
0
,
ethernetSource
,
ethernetDestination
,
EthernetType
.
IpV4
);
IpV4Datagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
IpV4Protocol
.
InternetGroupManagementProtocol
,
ipV4Ttl
,
IpV4Protocol
.
InternetGroupManagementProtocol
,
null
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
IgmpDatagram
.
HeaderLength
);
IgmpDatagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
+
ipHeaderLength
,
...
...
@@ -601,7 +601,7 @@ namespace PcapDotNet.Packets
IpV4Datagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
IpV4Protocol
.
Udp
,
ipV4Ttl
,
IpV4Protocol
.
Udp
,
null
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
transportLength
);
...
...
@@ -661,7 +661,7 @@ namespace PcapDotNet.Packets
IpV4Datagram
.
WriteHeader
(
buffer
,
EthernetDatagram
.
HeaderLength
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
IpV4Protocol
.
Tcp
,
ipV4Ttl
,
IpV4Protocol
.
Tcp
,
null
,
ipV4SourceAddress
,
ipV4DestinationAddress
,
ipV4Options
,
transportLength
);
...
...
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder2.cs
View file @
b2293f3d
...
...
@@ -185,6 +185,7 @@ namespace PcapDotNet.Packets
Fragmentation
=
IpV4Fragmentation
.
None
;
Ttl
=
0
;
Protocol
=
null
;
HeaderChecksum
=
null
;
Source
=
IpV4Address
.
Zero
;
Destination
=
IpV4Address
.
Zero
;
Options
=
IpV4Options
.
None
;
...
...
@@ -200,6 +201,8 @@ namespace PcapDotNet.Packets
public
IpV4Protocol
?
Protocol
{
get
;
set
;
}
public
ushort
?
HeaderChecksum
{
get
;
set
;
}
public
IpV4Address
Source
{
get
;
set
;
}
public
IpV4Address
Destination
{
get
;
set
;
}
...
...
@@ -238,7 +241,7 @@ namespace PcapDotNet.Packets
IpV4Datagram
.
WriteHeader
(
buffer
,
offset
,
TypeOfService
,
Identification
,
Fragmentation
,
Ttl
,
protocol
,
Ttl
,
protocol
,
HeaderChecksum
,
Source
,
Destination
,
Options
,
payloadLength
);
}
...
...
@@ -1080,6 +1083,11 @@ namespace PcapDotNet.Packets
public
class
PacketBuilder2
{
public
static
Packet
Build
(
DateTime
timestamp
,
params
ILayer
[]
layers
)
{
return
new
PacketBuilder2
(
layers
).
Build
(
timestamp
);
}
public
PacketBuilder2
(
params
ILayer
[]
layers
)
{
if
(
layers
.
Length
==
0
)
...
...
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