Skip to content

Commit

Permalink
Use PacketDotNet.Packet.Extract() in place of per-packet class GetEnc…
Browse files Browse the repository at this point in the history
…apsulated() methods
  • Loading branch information
chmorgan committed Feb 18, 2017
1 parent 62df7a3 commit 5b8e230
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
eth.SourceHwAddress = PhysicalAddress.Parse("00-11-22-33-44-55");
eth.DestinationHwAddress = PhysicalAddress.Parse("00-99-88-77-66-55");

var ip = PacketDotNet.IpPacket.GetEncapsulated(packet);
var ip = (PacketDotNet.IpPacket)packet.Extract(typeof(PacketDotNet.IpPacket));
if(ip != null)
{
Console.WriteLine("Original IP packet: " + ip.ToString());
Expand All @@ -104,7 +104,7 @@ private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
ip.DestinationAddress = System.Net.IPAddress.Parse("44.33.22.11");
ip.TimeToLive = 11;

var tcp = PacketDotNet.TcpPacket.GetEncapsulated(packet);
var tcp = (PacketDotNet.TcpPacket)packet.Extract(typeof(PacketDotNet.TcpPacket));
if (tcp != null)
{
Console.WriteLine("Original TCP packet: " + tcp.ToString());
Expand All @@ -120,7 +120,7 @@ private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
tcp.SequenceNumber = 800;
}

var udp = PacketDotNet.UdpPacket.GetEncapsulated(packet);
var udp = (PacketDotNet.UdpPacket)packet.Extract(typeof(PacketDotNet.UdpPacket));
if (udp != null)
{
Console.WriteLine("Original UDP packet: " + udp.ToString());
Expand Down
2 changes: 1 addition & 1 deletion Examples/Example6.DumpTCP/Example6.DumpTCP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static void device_OnPacketArrival(object sender, CaptureEventArgs e)

var packet = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);

var tcpPacket = PacketDotNet.TcpPacket.GetEncapsulated(packet);
var tcpPacket = (PacketDotNet.TcpPacket)packet.Extract(typeof(PacketDotNet.TcpPacket));
if(tcpPacket != null)
{
var ipPacket = (PacketDotNet.IpPacket)tcpPacket.ParentPacket;
Expand Down
2 changes: 1 addition & 1 deletion Examples/WakeOnLan/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static void device_OnPacketArrival(object sender, CaptureEventArgs e)
if(packet == null)
return;

var wol = PacketDotNet.WakeOnLanPacket.GetEncapsulated(packet);
var wol = (PacketDotNet.WakeOnLanPacket)packet.Extract(typeof(PacketDotNet.WakeOnLanPacket));
if(wol.PayloadData != null)
{
PrintHex(wol.DestinationMAC.GetAddressBytes());
Expand Down
2 changes: 1 addition & 1 deletion SharpPcap/ARP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public PhysicalAddress Resolve(System.Net.IPAddress destIP,
var packet = PacketDotNet.Packet.ParsePacket(reply.LinkLayerType, reply.Data);

// is this an arp packet?
arpPacket = PacketDotNet.ARPPacket.GetEncapsulated(packet);
arpPacket = (PacketDotNet.ARPPacket)packet.Extract(typeof(PacketDotNet.ARPPacket));
if(arpPacket == null)
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion Test/CaptureFileReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void SetFilter()
if(rawPacket != null)
{
Packet p = Packet.ParsePacket(rawPacket.LinkLayerType, rawPacket.Data);
var udpPacket = UdpPacket.GetEncapsulated(p);
var udpPacket = (UdpPacket)p.Extract(typeof(UdpPacket));
Assert.IsNotNull(udpPacket);
int dnsPort = 53;
Assert.AreEqual(dnsPort, udpPacket.DestinationPort);
Expand Down

0 comments on commit 5b8e230

Please sign in to comment.