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
4b703916
Commit
4b703916
authored
Aug 09, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TCP
parent
647277c1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
161 additions
and
34 deletions
+161
-34
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+5
-5
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+1
-1
UdpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/UdpTests.cs
+2
-1
IpV4Datagram.cs
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
+1
-1
PacketBuilder.cs
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder.cs
+1
-1
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+4
-1
TcpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Transport/TcpDatagram.cs
+89
-0
TransportDatagram.cs
...Net/src/PcapDotNet.Packets/Transport/TransportDatagram.cs
+53
-0
UdpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Transport/UdpDatagram.cs
+5
-24
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
4b703916
...
...
@@ -270,21 +270,21 @@ namespace PcapDotNet.Core.Test
// Normal
TestGetStatistics
(
SourceMac
,
DestinationMac
,
NumPacketsToSend
,
NumStatisticsToGather
,
int
.
MaxValue
,
5
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumStatisticsToGather
,
NumPacketsToSend
,
NumStatisticsToGather
,
NumStatisticsToGather
+
0.0
2
);
PacketCommunicatorReceiveResult
.
Ok
,
NumStatisticsToGather
,
NumPacketsToSend
,
NumStatisticsToGather
,
NumStatisticsToGather
+
0.0
4
);
// Wait for less statistics
TestGetStatistics
(
SourceMac
,
DestinationMac
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
int
.
MaxValue
,
5
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumStatisticsToGather
/
2
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
NumStatisticsToGather
/
2
+
0.0
2
);
PacketCommunicatorReceiveResult
.
Ok
,
NumStatisticsToGather
/
2
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
NumStatisticsToGather
/
2
+
0.0
4
);
// Wait for more statistics
TestGetStatistics
(
SourceMac
,
DestinationMac
,
NumPacketsToSend
,
0
,
int
.
MaxValue
,
5.5
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
5
,
NumPacketsToSend
,
5.5
,
5.5
2
);
PacketCommunicatorReceiveResult
.
None
,
5
,
NumPacketsToSend
,
5.5
,
5.5
4
);
// Break loop
TestGetStatistics
(
SourceMac
,
DestinationMac
,
NumPacketsToSend
,
NumStatisticsToGather
,
0
,
5
,
PacketSize
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0
,
0
,
0.0
2
);
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0
,
0
,
0.0
4
);
TestGetStatistics
(
SourceMac
,
DestinationMac
,
NumPacketsToSend
,
NumStatisticsToGather
,
NumStatisticsToGather
/
2
,
5
,
PacketSize
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
NumStatisticsToGather
/
2
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
NumStatisticsToGather
/
2
+
0.0
2
);
PacketCommunicatorReceiveResult
.
BreakLoop
,
NumStatisticsToGather
/
2
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
NumStatisticsToGather
/
2
+
0.0
4
);
}
[
TestMethod
]
...
...
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
4b703916
...
...
@@ -12,7 +12,7 @@ using PcapDotNet.Packets;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.
Udp
;
using
PcapDotNet.Packets.
Transport
;
using
PcapDotNet.TestUtils
;
namespace
PcapDotNet.Core.Test
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/UdpTests.cs
View file @
4b703916
...
...
@@ -3,7 +3,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.
Udp
;
using
PcapDotNet.Packets.
Transport
;
using
PcapDotNet.TestUtils
;
namespace
PcapDotNet.Packets.Test
...
...
@@ -103,6 +103,7 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
UdpDatagram
.
HeaderLength
+
udpPayload
.
Length
,
packet
.
Ethernet
.
IpV4
.
Udp
.
TotalLength
,
"Total Length"
);
Assert
.
IsTrue
(!
udpCalculateChecksum
&&
packet
.
Ethernet
.
IpV4
.
Udp
.
Checksum
==
0
||
packet
.
Ethernet
.
IpV4
.
IsTransportChecksumCorrect
,
"IsTransportChecksumCorrect"
);
Assert
.
AreEqual
(
udpPayload
,
packet
.
Ethernet
.
IpV4
.
Udp
.
Payload
,
"Payload"
);
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
View file @
4b703916
...
...
@@ -2,7 +2,7 @@
using
System.Collections
;
using
System.Linq
;
using
System.Text
;
using
PcapDotNet.Packets.
Udp
;
using
PcapDotNet.Packets.
Transport
;
namespace
PcapDotNet.Packets.IpV4
{
...
...
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder.cs
View file @
4b703916
using
System
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.
Udp
;
using
PcapDotNet.Packets.
Transport
;
namespace
PcapDotNet.Packets
{
...
...
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
4b703916
...
...
@@ -101,7 +101,10 @@
<Compile
Include=
"Packet.cs"
/>
<Compile
Include=
"PacketBuilder.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Udp\UdpDatagram.cs"
/>
<Compile
Include=
"Transport\TcpDatagram.cs"
/>
<Compile
Include=
"Transport\TcpFlags.cs"
/>
<Compile
Include=
"Transport\TransportDatagram.cs"
/>
<Compile
Include=
"Transport\UdpDatagram.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"..\PcapDotNet.snk"
/>
...
...
PcapDotNet/src/PcapDotNet.Packets/Transport/TcpDatagram.cs
0 → 100644
View file @
4b703916
namespace
PcapDotNet.Packets.Transport
{
/// <summary>
/// TCP Header Format
/// +-----+-------------+----------+----+-----+-----+-----+-----+-----+-----+-----+-----+------------------+
/// | Bit | 0-3 | 4-6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16-31 |
/// +-----+-------------+----------+----+-----+-----+-----+-----+-----+-----+-----+-----+------------------+
/// | 0 | Source Port | Destination Port |
/// +-----+-----------------------------------------------------------------------------+------------------+
/// | 32 | Sequence Number |
/// +-----+------------------------------------------------------------------------------------------------+
/// | 64 | Acknowledgment Number |
/// +-----+-------------+----------+----+-----+-----+-----+-----+-----+-----+-----+-----+------------------+
/// | 96 | Data Offset | Reserved | NS | CWR | ECE | URG | ACK | PSH | RST | SYN | FIN | Window |
/// +-----+-------------+----------+----+-----+-----+-----+-----+-----+-----+-----+-----+------------------+
/// | 128 | Checksum | Urgent Pointer |
/// +-----+-----------------------------------------------------------------------------+------------------+
/// | 160 | Options + Padding |
/// +-----+------------------------------------------------------------------------------------------------+
/// </summary>
public
class
TcpDatagram
:
TransportDatagram
{
private
static
class
Offset
{
public
const
int
SequenceNumber
=
4
;
public
const
int
AcknowledgmentNumber
=
8
;
public
const
int
HeaderLength
=
12
;
public
const
int
Flags
=
12
;
public
const
int
Window
=
14
;
public
const
int
Checksum
=
16
;
public
const
int
UrgentPointer
=
18
;
public
const
int
Options
=
20
;
}
public
TcpDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
:
base
(
buffer
,
offset
,
length
)
{
}
/// <summary>
/// The sequence number of the first data octet in this segment (except when SYN is present).
/// If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.
/// </summary>
public
uint
SequenceNumber
{
get
{
return
ReadUInt
(
Offset
.
SequenceNumber
,
Endianity
.
Big
);
}
}
/// <summary>
/// If the ACK control bit is set this field contains the value of the next sequence number
/// the sender of the segment is expecting to receive.
/// Once a connection is established this is always sent.
/// </summary>
public
uint
AcknowledgmentNumber
{
get
{
return
ReadUInt
(
Offset
.
AcknowledgmentNumber
,
Endianity
.
Big
);
}
}
/// <summary>
/// The number of bytes in the TCP Header.
/// This indicates where the data begins.
/// The TCP header (even one including options) is an integral number of 32 bits (4 bytes) long.
/// </summary>
public
int
HeaderLength
{
get
{
return
4
*
(
this
[
Offset
.
HeaderLength
]
>>
4
);
}
}
public
TcpFlags
Flags
{
get
{
return
(
TcpFlags
)(
ReadUShort
(
Offset
.
Flags
,
Endianity
.
Big
)
&
0x01FF
);
}
}
public
ushort
Window
{
get
{
return
ReadUShort
(
Offset
.
Window
,
Endianity
.
Big
);
}
}
public
ushort
Checksum
{
get
{
return
ReadUShort
(
Offset
.
Checksum
,
Endianity
.
Big
);
}
}
public
ushort
UrgentPointer
{
get
{
return
ReadUShort
(
Offset
.
UrgentPointer
,
Endianity
.
Big
);
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Transport/TransportDatagram.cs
0 → 100644
View file @
4b703916
namespace
PcapDotNet.Packets.Transport
{
/// <summary>
/// Contains the common part of UDP and TCP.
///
/// Format:
/// +-----+-------------+----------+-----+-----+-----+-----+-----+-----+------------------+
/// | Bit | 0-4 | 4-9 | 10 | 11 | 12 | 13 | 14 | 15 | 16-31 |
/// +-----+-------------+----------+-----+-----+-----+-----+-----+-----+------------------+
/// | 0 | Source Port | Destination Port |
/// +-----+------------------------------------------------------------+------------------+
/// | 32 | Sequence Number |
/// +-----+-------------------------------------------------------------------------------+
/// </summary>
public
abstract
class
TransportDatagram
:
Datagram
{
private
static
class
Offset
{
public
const
int
SourcePort
=
0
;
public
const
int
DestinationPort
=
2
;
}
/// <summary>
/// Indicates the port of the sending process.
/// In UDP, this field is optional and may only be assumed to be the port
/// to which a reply should be addressed in the absence of any other information.
/// If not used in UDP, a value of zero is inserted.
/// </summary>
public
ushort
SourcePort
{
get
{
return
ReadUShort
(
Offset
.
SourcePort
,
Endianity
.
Big
);
}
}
/// <summary>
/// Destination Port has a meaning within the context of a particular internet destination address.
/// </summary>
public
ushort
DestinationPort
{
get
{
return
ReadUShort
(
Offset
.
DestinationPort
,
Endianity
.
Big
);
}
}
protected
static
void
WriteHeader
(
byte
[]
buffer
,
int
offset
,
ushort
sourcePort
,
ushort
destinationPort
)
{
buffer
.
Write
(
offset
+
Offset
.
SourcePort
,
sourcePort
,
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
DestinationPort
,
destinationPort
,
Endianity
.
Big
);
}
protected
TransportDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
:
base
(
buffer
,
offset
,
length
)
{
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/
Udp
/UdpDatagram.cs
→
PcapDotNet/src/PcapDotNet.Packets/
Transport
/UdpDatagram.cs
View file @
4b703916
using
System
;
namespace
PcapDotNet.Packets.
Udp
namespace
PcapDotNet.Packets.
Transport
{
/// <summary>
/// This User Datagram Protocol (UDP) is defined to make available a datagram mode of packet-switched computer communication
...
...
@@ -26,7 +26,7 @@ namespace PcapDotNet.Packets.Udp
/// +---------------- ...
/// </summary>
public
class
UdpDatagram
:
Datagram
public
class
UdpDatagram
:
Transport
Datagram
{
/// <summary>
/// The number of bytes the datagram header takes.
...
...
@@ -35,32 +35,14 @@ namespace PcapDotNet.Packets.Udp
private
static
class
Offset
{
public
const
int
SourcePort
=
0
;
public
const
int
DestinationPort
=
2
;
//
public const int SourcePort = 0;
//
public const int DestinationPort = 2;
public
const
int
TotalLength
=
4
;
public
const
int
Checksum
=
6
;
}
internal
const
int
ChecksumOffset
=
Offset
.
Checksum
;
/// <summary>
/// Source Port is an optional field, when meaningful, it indicates the port of the sending process,
/// and may be assumed to be the port to which a reply should be addressed in the absence of any other information.
/// If not used, a value of zero is inserted.
/// </summary>
public
ushort
SourcePort
{
get
{
return
ReadUShort
(
Offset
.
SourcePort
,
Endianity
.
Big
);
}
}
/// <summary>
/// Destination Port has a meaning within the context of a particular internet destination address.
/// </summary>
public
ushort
DestinationPort
{
get
{
return
ReadUShort
(
Offset
.
DestinationPort
,
Endianity
.
Big
);
}
}
/// <summary>
/// The length in octets of this user datagram including this header and the data.
/// (This means the minimum value of the length is eight.)
...
...
@@ -94,8 +76,7 @@ namespace PcapDotNet.Packets.Udp
internal
static
void
WriteHeader
(
byte
[]
buffer
,
int
offset
,
ushort
sourcePort
,
ushort
destinationPort
,
int
payloadLength
)
{
buffer
.
Write
(
offset
+
Offset
.
SourcePort
,
sourcePort
,
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
DestinationPort
,
destinationPort
,
Endianity
.
Big
);
WriteHeader
(
buffer
,
offset
,
sourcePort
,
destinationPort
);
buffer
.
Write
(
offset
+
Offset
.
TotalLength
,
(
ushort
)(
HeaderLength
+
payloadLength
),
Endianity
.
Big
);
}
...
...
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