Skip to content

Add Dhcp-Support #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets;
using PcapDotNet.Packets.Dhcp;
using PcapDotNet.Packets.Dns;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Gre;
Expand Down Expand Up @@ -390,24 +391,53 @@ private static void CreateRandomIpPayload(Random random, Layer ipLayer, List<ILa
}
}

private static void CreateRandomUdpPayload(Random random, UdpLayer udpLayer, List<ILayer> layers)
{
if (random.NextBool(20))
{
// Finish with payload.
PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100));
layers.Add(payloadLayer);
return;
}

DnsLayer dnsLayer = random.NextDnsLayer();
layers.Add(dnsLayer);

ushort specialPort = (ushort)(random.NextBool() ? 53 : 5355);
if (dnsLayer.IsQuery)
udpLayer.DestinationPort = specialPort;
else
udpLayer.SourcePort = specialPort;
private static void CreateRandomUdpPayload(Random random, UdpLayer udpLayer, List<ILayer> layers)
{
if (random.NextBool(20))
{
// Finish with payload.
PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(100));
layers.Add(payloadLayer);
return;
}

switch (random.Next(0, 2))
Copy link
Contributor

@bricknerb bricknerb Jan 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this random.NextBool() instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep it because there may be more than two possible payloads in the future

{
case 0:
{
DnsLayer dnsLayer = random.NextDnsLayer();
layers.Add(dnsLayer);

ushort specialPort = (ushort)(random.NextBool() ? 53 : 5355);
if (dnsLayer.IsQuery)
udpLayer.DestinationPort = specialPort;
else
udpLayer.SourcePort = specialPort;
break;
}

case 1:
{
DhcpLayer dhcpLayer = random.NextDhcpLayer();
layers.Add(dhcpLayer);

if (random.NextBool())
{
udpLayer.SourcePort = 67 ;
udpLayer.DestinationPort = 68;
}
else
{
udpLayer.SourcePort = 68;
udpLayer.DestinationPort = 67;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 432-439 seem to repeat lines 424-431.


break;
}

default:
throw new InvalidOperationException("Invalid value.");
}
}

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