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
02a7c395
Commit
02a7c395
authored
Dec 05, 2015
by
Boaz Brickner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid returning negative Padding when the Ethernet's payload is big enough.
parent
c30aa3b1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
EthernetTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
+21
-0
EthernetBaseDatagram.cs
...t/src/PcapDotNet.Packets/Ethernet/EthernetBaseDatagram.cs
+6
-4
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
View file @
02a7c395
using
System
;
using
System.Collections.ObjectModel
;
using
System.Diagnostics.CodeAnalysis
;
using
System.Linq
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Arp
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV6
;
...
...
@@ -132,5 +135,23 @@ namespace PcapDotNet.Packets.Test
Assert
.
IsTrue
(
packet
.
IsValid
);
Assert
.
AreEqual
(
DataSegment
.
Empty
,
packet
.
Ethernet
.
Padding
);
}
[
TestMethod
]
public
void
PayloadTooBigForPadding
()
{
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
ArpLayer
{
ProtocolType
=
EthernetType
.
IpV4
,
Operation
=
ArpOperation
.
DynamicReverseError
,
SenderHardwareAddress
=
new
byte
[
12
].
AsReadOnly
(),
SenderProtocolAddress
=
new
byte
[
22
].
AsReadOnly
(),
TargetHardwareAddress
=
new
byte
[
12
].
AsReadOnly
(),
TargetProtocolAddress
=
new
byte
[
22
].
AsReadOnly
(),
});
Assert
.
IsTrue
(
packet
.
IsValid
);
Assert
.
AreEqual
(
DataSegment
.
Empty
,
packet
.
Ethernet
.
Padding
);
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Ethernet/EthernetBaseDatagram.cs
View file @
02a7c395
...
...
@@ -45,9 +45,11 @@ namespace PcapDotNet.Packets.Ethernet
if
(
payloadByEtherType
==
null
)
return
null
;
int
payloadLength
=
PayloadByEtherType
.
Length
;
return
new
DataSegment
(
Buffer
,
StartOffset
+
HeaderLength
+
payloadLength
,
60
-
HeaderLength
-
payloadLength
);
int
payloadLength
=
payloadByEtherType
.
Length
;
int
dataLength
=
HeaderLength
+
payloadLength
;
if
(
dataLength
>=
60
)
return
DataSegment
.
Empty
;
return
new
DataSegment
(
Buffer
,
StartOffset
+
dataLength
,
60
-
dataLength
);
}
}
...
...
@@ -106,7 +108,7 @@ namespace PcapDotNet.Packets.Ethernet
if
(
payloadByEtherType
==
null
)
return
null
;
int
payloadLength
=
P
ayloadByEtherType
.
Length
;
int
payloadLength
=
p
ayloadByEtherType
.
Length
;
return
new
DataSegment
(
Buffer
,
StartOffset
+
HeaderLength
+
payloadLength
,
Length
-
HeaderLength
-
payloadLength
);
}
}
...
...
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