Skip to content

Commit d2faae8

Browse files
committed
add dhcp support
1 parent 49164e4 commit d2faae8

File tree

90 files changed

+6260
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+6260
-17
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
using PcapDotNet.Packets.Dhcp;
9+
using PcapDotNet.Packets.Ethernet;
10+
using PcapDotNet.Packets.IpV4;
11+
using PcapDotNet.Packets.TestUtils;
12+
using PcapDotNet.Packets.Transport;
13+
14+
namespace PcapDotNet.Packets.Test
15+
{
16+
/// <summary>
17+
/// Summary description for ArpTests
18+
/// </summary>
19+
[TestClass]
20+
[ExcludeFromCodeCoverage]
21+
public class DhcpTests
22+
{
23+
/// <summary>
24+
/// Gets or sets the test context which provides
25+
/// information about and functionality for the current test run.
26+
/// </summary>
27+
public TestContext TestContext { get; set; }
28+
29+
#region Additional test attributes
30+
31+
//
32+
// You can use the following additional attributes as you write your tests:
33+
//
34+
// Use ClassInitialize to run code before running the first test in the class
35+
// [ClassInitialize()]
36+
// public static void MyClassInitialize(TestContext testContext) { }
37+
//
38+
// Use ClassCleanup to run code after all tests in a class have run
39+
// [ClassCleanup()]
40+
// public static void MyClassCleanup() { }
41+
//
42+
// Use TestInitialize to run code before running each test
43+
// [TestInitialize()]
44+
// public void MyTestInitialize() { }
45+
//
46+
// Use TestCleanup to run code after each test has run
47+
// [TestCleanup()]
48+
// public void MyTestCleanup() { }
49+
//
50+
51+
#endregion Additional test attributes
52+
53+
[TestMethod]
54+
public void RandomDhcpTest()
55+
{
56+
int seed = new Random().Next();
57+
Console.WriteLine("Seed: " + seed);
58+
Random random = new Random(seed);
59+
60+
for (int i = 0; i != 1000; ++i)
61+
{
62+
EthernetLayer ethernetLayer = random.NextEthernetLayer(EthernetType.None);
63+
64+
IpV4Layer ipV4Layer = random.NextIpV4Layer(null);
65+
ipV4Layer.HeaderChecksum = null;
66+
67+
UdpLayer udpLayer = random.NextUdpLayer();
68+
udpLayer.Checksum = null;
69+
70+
DhcpLayer dhcpLayer = random.NextDhcpLayer();
71+
72+
Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, ipV4Layer, udpLayer, dhcpLayer);
73+
74+
Assert.IsTrue(packet.IsValid, "IsValid");
75+
DhcpLayer actualLayer = (DhcpLayer)packet.Ethernet.Ip.Udp.Dhcp.ExtractLayer();
76+
if (!Object.Equals(dhcpLayer, actualLayer))
77+
{
78+
Console.WriteLine(actualLayer);
79+
}
80+
Assert.AreEqual(dhcpLayer, actualLayer, "DHCP Layer");
81+
}
82+
}
83+
}
84+
}

PcapDotNet/src/PcapDotNet.Packets.Test/PcapDotNet.Packets.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<Compile Include="DatagramTests.cs" />
7676
<Compile Include="DataLinkTests.cs" />
7777
<Compile Include="DataSegmentTests.cs" />
78+
<Compile Include="DhcpTests.cs" />
7879
<Compile Include="DnsTests.cs" />
7980
<Compile Include="EndianitiyTests.cs" />
8081
<Compile Include="EthernetTests.cs" />

PcapDotNet/src/PcapDotNet.Packets.TestUtils/PcapDotNet.Packets.TestUtils.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<ItemGroup>
7777
<Compile Include="HexEncoding.cs" />
7878
<Compile Include="RandomArpExtensions.cs" />
79+
<Compile Include="RandomDhcpExtensions.cs" />
7980
<Compile Include="RandomDnsExtensions.cs" />
8081
<Compile Include="RandomEthernetExtensions.cs" />
8182
<Compile Include="RandomGreExtensions.cs" />

0 commit comments

Comments
 (0)