dotpcap / sharppcap

Official repository - Fully managed, cross platform (Windows, Mac, Linux) .NET library for capturing packets
1.31k stars 267 forks source link

Converting from old v1.x API #370

Closed InteXX closed 2 years ago

InteXX commented 2 years ago

I'm updating some very old code that uses SharpPCap v1.0.6, and I'm hitting some dead ends. Suggestions, please?

  1. this._Time = packet.PcapHeader.Date; (there is no PcapHeader property)
  2. TCPPacket and UDPPacket references (classes no longer exist)
  3. _offlinedevice = SharpPcap.GetPcapOfflineDevice(this.FileName); (not finding an equivalent method)
  4. while ((packet = _offlinedevice.PcapGetNextPacket()) != null) {} (construct seems no longer valid)
  5. if (device.PcapDumpOpened) (property/field no longer exists)
  6. device.PcapDump(packet); (method no longer exists)
  7. device.PcapOnPacketArrival += new SharpPcap.PacketArrivalEvent(device_PcapOnPacketArrival); (event no longer exists)
  8. device.PcapOpen(true, 1000); (syntax is no longer valid)
  9. device.PcapDumpOpen(this.FileName); (method no longer exists)
kayoub5 commented 2 years ago
1. `this._Time = packet.PcapHeader.Date;` (there is no `PcapHeader` property)

packet.Header https://github.com/dotpcap/sharppcap/blob/master/SharpPcap/PacketCapture.cs

2. `TCPPacket` and `UDPPacket` references (classes no longer exist)

See https://github.com/dotpcap/packetnet

3. `_offlinedevice = SharpPcap.GetPcapOfflineDevice(this.FileName);` (not finding an equivalent method)

CaptureFileReaderDevice

4. `while ((packet = _offlinedevice.PcapGetNextPacket()) != null) {}` (construct seems no longer valid)

See Example4

5. `if (device.PcapDumpOpened)` (property/field no longer exists)

IsOpen

6. `device.PcapDump(packet);` (method no longer exists)

Example6

7. `device.PcapOnPacketArrival += new SharpPcap.PacketArrivalEvent(device_PcapOnPacketArrival);` (event no longer exists)

OnPacketArrival

8. `device.PcapOpen(true, 1000);` (syntax is no longer valid)

device.Open(....)

9. `device.PcapDumpOpen(this.FileName);` (method no longer exists)

CaptureFileWriterDevice

InteXX commented 2 years ago

Thank you very much. That was surprisingly fast.

InteXX commented 2 years ago

Hm... still none of it is working, though. I'd better slow down and provide more detail for each one.

First up: this._Time = packet.PcapHeader.Date; (there is no PcapHeader property)

Here's the snippet:

    public bool FillConnection(Packet packet)
    {
      if (packet == null)
        return false;
      IPEndPoint srcAddress = null;
      IPEndPoint dstAddress = null;
      int UsefulTraffic = 0;//Length;
      int RealTraffic = 0;//Length;
      this._Direction = Direction.None;
      this._IsValidConnection = false;
      this._Time = packet.PcapHeader.Date;
    }

The packet paremeter was originally of type Tamir.IPLib.Packets.Packet, not the new SharpPcap.PacketCapture. What would be the equivalent for this?

kayoub5 commented 2 years ago

Your code is way too old to map things one to one, PacketCapture contains the raw data from winpcap/LibPcap (timestamp and data bytes) IpPacket is the result of decoding the PacketCapture data and contains fields like ip addresses

InteXX commented 2 years ago

That's what I was afraid of.

But thanks for the clarification.

chmorgan commented 2 years ago

Have you looked at some of the sharppcap and packet net examples? While it isn’t a one to one mapping it should be relatively apparent how to adjust for the api changes and we can help answer specific questions.

Regards, Chris

On Sun, Feb 6, 2022 at 7:05 PM Jeff Bowman @.***> wrote:

That's what I was afraid of.

But thanks for the clarification.

— Reply to this email directly, view it on GitHub https://github.com/dotpcap/sharppcap/issues/370#issuecomment-1030946441, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJH4AGZQHOVJ6MWVKEG643UZ4EDVANCNFSM5NUQMLIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

InteXX commented 2 years ago

@chmorgan

That's a gracious offer... I believe I'll take you up on that.

I'm presently juggling several projects, though, so it's going to be slow going.

chmorgan commented 2 years ago

Closing due to inactivity. Please reopen if you've got further questions!

InteXX commented 2 years ago

Thanks Chris. I've just been so doggone busy...