Skip to content

Commit 69ea914

Browse files
committed
finish dhcp-support with documentation and fixes
1 parent d2faae8 commit 69ea914

File tree

107 files changed

+4911
-2214
lines changed

Some content is hidden

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

107 files changed

+4911
-2214
lines changed

PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Xml.Linq;
1010
using Microsoft.VisualStudio.TestTools.UnitTesting;
1111
using PcapDotNet.Packets;
12+
using PcapDotNet.Packets.Dhcp;
1213
using PcapDotNet.Packets.Dns;
1314
using PcapDotNet.Packets.Ethernet;
1415
using PcapDotNet.Packets.Gre;
@@ -390,24 +391,58 @@ private static void CreateRandomIpPayload(Random random, Layer ipLayer, List<ILa
390391
}
391392
}
392393

393-
private static void CreateRandomUdpPayload(Random random, UdpLayer udpLayer, List<ILayer> layers)
394-
{
395-
if (random.NextBool(20))
396-
{
397-
// Finish with payload.
398-
PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100));
399-
layers.Add(payloadLayer);
400-
return;
401-
}
402-
403-
DnsLayer dnsLayer = random.NextDnsLayer();
404-
layers.Add(dnsLayer);
405-
406-
ushort specialPort = (ushort)(random.NextBool() ? 53 : 5355);
407-
if (dnsLayer.IsQuery)
408-
udpLayer.DestinationPort = specialPort;
409-
else
410-
udpLayer.SourcePort = specialPort;
394+
private static void CreateRandomUdpPayload(Random random, UdpLayer udpLayer, List<ILayer> layers)
395+
{
396+
if (random.NextBool(20))
397+
{
398+
// Finish with payload.
399+
PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100));
400+
layers.Add(payloadLayer);
401+
return;
402+
}
403+
404+
switch (random.Next(0, 2))
405+
{
406+
case 0:
407+
{
408+
DnsLayer dnsLayer = random.NextDnsLayer();
409+
layers.Add(dnsLayer);
410+
411+
ushort specialPort = (ushort)(random.NextBool() ? 53 : 5355);
412+
if (dnsLayer.IsQuery)
413+
udpLayer.DestinationPort = specialPort;
414+
else
415+
udpLayer.SourcePort = specialPort;
416+
break;
417+
}
418+
419+
case 1:
420+
{
421+
DhcpLayer dhcpLayer = random.NextDhcpLayer();
422+
layers.Add(dhcpLayer);
423+
424+
if (random.NextBool())
425+
{
426+
udpLayer.SourcePort = (ushort)(random.NextBool() ? 67 : 68);
427+
}
428+
else
429+
{
430+
udpLayer.DestinationPort = 5355;
431+
}
432+
if (random.NextBool())
433+
{
434+
udpLayer.SourcePort = (ushort)(random.NextBool() ? 67 : 68);
435+
}
436+
else
437+
{
438+
udpLayer.SourcePort = 5355;
439+
}
440+
break;
441+
}
442+
443+
default:
444+
throw new InvalidOperationException("Invalid value.");
445+
}
411446
}
412447

413448
private static void CreateRandomTcpPayload(Random random, TcpLayer tcpLayer, List<ILayer> layers)

0 commit comments

Comments
 (0)