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
1f35830f
Commit
1f35830f
authored
Apr 19, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Datagram.ToMemoryStream() method.
Added default constructor for TcpLayer.
parent
b76f996a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
0 deletions
+38
-0
DatagramTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
+27
-0
Datagram.cs
PcapDotNet/src/PcapDotNet.Packets/Datagram.cs
+6
-0
TcpLayer.cs
PcapDotNet/src/PcapDotNet.Packets/Transport/TcpLayer.cs
+5
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/DatagramTests.cs
View file @
1f35830f
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.IO
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.Transport
;
namespace
PcapDotNet.Packets.Test
{
...
...
@@ -101,5 +104,29 @@ namespace PcapDotNet.Packets.Test
Datagram
data
=
new
Datagram
(
new
byte
[]{
1
,
2
,
3
});
Assert
.
IsTrue
(
data
.
IsValid
);
}
[
TestMethod
]
public
void
DatagramToMemoryStreamTest
()
{
Datagram
tcpPayload
=
new
Datagram
(
new
byte
[]
{
1
,
2
,
3
});
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
TcpLayer
(),
new
PayloadLayer
{
Data
=
tcpPayload
});
using
(
MemoryStream
stream
=
packet
.
Ethernet
.
IpV4
.
Tcp
.
Payload
.
ToMemoryStream
())
{
Assert
.
IsTrue
(
stream
.
CanRead
,
"CanRead"
);
Assert
.
IsTrue
(
stream
.
CanSeek
,
"CanSeek"
);
Assert
.
IsFalse
(
stream
.
CanTimeout
,
"CanTimeout"
);
Assert
.
IsFalse
(
stream
.
CanWrite
,
"CanWrite"
);
Assert
.
AreEqual
(
tcpPayload
.
Length
,
stream
.
Length
);
for
(
int
i
=
0
;
i
!=
tcpPayload
.
Length
;
++
i
)
{
Assert
.
AreEqual
(
i
,
stream
.
Position
);
Assert
.
AreEqual
(
i
+
1
,
stream
.
ReadByte
());
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Datagram.cs
View file @
1f35830f
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Ethernet
;
...
...
@@ -63,6 +64,11 @@ namespace PcapDotNet.Packets
get
{
return
_buffer
[
StartOffset
+
offset
];
}
}
public
MemoryStream
ToMemoryStream
()
{
return
new
MemoryStream
(
Buffer
,
StartOffset
,
Length
,
false
,
false
);
}
/// <summary>
/// A datagram is checked for validity according to the protocol.
/// </summary>
...
...
PcapDotNet/src/PcapDotNet.Packets/Transport/TcpLayer.cs
View file @
1f35830f
...
...
@@ -9,6 +9,11 @@ namespace PcapDotNet.Packets.Transport
/// </summary>
public
class
TcpLayer
:
TransportLayer
{
public
TcpLayer
()
{
Options
=
TcpOptions
.
None
;
}
/// <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.
...
...
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