|
9 | 9 | using System.Xml.Linq;
|
10 | 10 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
11 | 11 | using PcapDotNet.Packets;
|
| 12 | +using PcapDotNet.Packets.Dhcp; |
12 | 13 | using PcapDotNet.Packets.Dns;
|
13 | 14 | using PcapDotNet.Packets.Ethernet;
|
14 | 15 | using PcapDotNet.Packets.Gre;
|
@@ -390,24 +391,58 @@ private static void CreateRandomIpPayload(Random random, Layer ipLayer, List<ILa
|
390 | 391 | }
|
391 | 392 | }
|
392 | 393 |
|
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 | + } |
411 | 446 | }
|
412 | 447 |
|
413 | 448 | private static void CreateRandomTcpPayload(Random random, TcpLayer tcpLayer, List<ILayer> layers)
|
|
0 commit comments