Hello all,
I'm trying to retrieve only the data of a packet that I've received. The packet can come in on a loopback adapter or Ethernet adapter. Here's an example of a packet that I want to get the data from viewed in Wireshark:
The data layer is highlighted.
I can't seem to find a way to strip the other layers out and just get to the underlying data. At first I tried removing this header with a hard-coded number. This worked fine whenever I receive packets on my wifi adapter, like in the example above where the header is 42 bytes long. But then, if I try using the same code to receive on the loopback adapter for debugging, the header's size is different, so I end up truncating part of the data that I need.
I've tried poking around the different layers and datagrams and such, and I've come up short. I can't seem to find a single, distinct way to know exactly how long the headers/layers before the data are so I can strip them off.
I did stumble across an internal member, "StartOffset", when watching a local Datagram variable while debugging in Visual Studio which seems to have what I need. By getting the payload datagram via:
Datagram payloadDgram = packet.IpV4.Udp.Payload;
Inspecting payloadDgram shows this StartOffset member, and it appears to be the length that I need to cut off of Data to get what I want. But both StartOffset and the Data are not accessible members, so I'm confused how they even exist...
Anyway, how can I go about doing this?