Skip to content
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

Using Example 4: basic cap no callback why is the Local Host data Ethernet II and not IP #265

Open
Terry550 opened this issue Mar 31, 2021 · 20 comments

Comments

@Terry550
Copy link

I ran your example 4, basic cap no callback to capture Local Host data, and then opened my saved .pcap file in Wireshark (v3.4.4).
It appears the local host data was recorded but not sure why it shows up in Wireshark as Ethernet II and not IP TCP.
Is this as expected?
Thanks
Terry

@Terry550
Copy link
Author

I've attached my VS2015 dotnetframework v4.6.1 solution and a pcap file I captured for loopback adapter.
Any help would be greatly appreciated.
Thanks
Terry
LoopBack_Capture_VS2015_NetFW4.6.1_SharpPcapv5.4.zip
EMS_EthernetMonitorServer_WPCAP_NPCAP LocalHost Example.zip

@chmorgan
Copy link
Collaborator

chmorgan commented Apr 1, 2021

Hi @Terry550. What adapter are you capturing from? I'm trying to recall the specifics, something about when you capture at the loopback layer where you end up losing the link layer type comes to mind.

Looking at the captured data it doesn't look like Wireshark can decode any of the packets. What happens if you capture from the same device from Wireshark?

@Terry550
Copy link
Author

Terry550 commented Apr 1, 2021 via email

@Terry550
Copy link
Author

Terry550 commented Apr 1, 2021

Hi chmorgan,
I have more info to provide. I updated to VS2019 and tried the framework 4.8 but had issues compiling it kept saying I need DotNetStandard 2.0 ref but I already had installed the Nuget packet DotNetStandard 2.0 for this project.
So I tried VS2019 with framework 4.6.1, same sample program with the same output results.

I then simultaneously captured your capture sample program (vs2015 version) along w/ wireshark to compare the results.
I compared the two (@same timetag) and found the difference seems to be that SharpPcap doesn't recognize Encapsulation type Null/Loopback. I attached pics of the comparison of the two.

WiresharkCapture
SharPcapCapture

Thanks for your help!
Terry

@Terry550
Copy link
Author

Terry550 commented Apr 1, 2021

I noticed Closed Issue #17 seems to talk about the same issue.
I'm using Nuget release SharpPcap v5.4 and PacketDotNet v1.2, Did the fix get rolled in a later version?
Did it get fixed for both Linux and windows?
Thanks,
Terry

@chmorgan
Copy link
Collaborator

chmorgan commented Apr 2, 2021

@Terry550 what capture library are you using? npcap 1.2? I'm asking because looking at your code there shouldn't be any modification to the packets by SharpPcap or npcap. So maybe Wireshark is writing to it differently?

@Terry550
Copy link
Author

Terry550 commented Apr 2, 2021

Hi chmorgan,
Thanks for getting back with me.
I'm using NPcap v1.20 and the file versions found in the System Npcap folder are:
wpcap.dll (1.10.1 - PRE-GIT)
packet.dll (5.1.20.305)

In your example I had to modify the following line because it would compile for me:
device.Open(mode: DeviceModes.Promiscuous | DeviceModes.DataTransferUdp | DeviceModes.NoCaptureLocal, read_timeout: readTimeoutMilliseconds);
to
device.Open(mode: DeviceMode.Promiscuous, read_timeout: readTimeoutMilliseconds);
Maybe that will be a hint.

Have you had a chance to run my solution to see if it gives you the same pcap output?
Thanks,
Terry

@Terry550
Copy link
Author

Terry550 commented Apr 2, 2021

I'm wondering if you have a newer version of libpcap since it says "PRE-GIT" when I look at the properties.
Also, maybe the newer version allows this device.Open method:
device.Open(mode: DeviceModes.Promiscuous | DeviceModes.DataTransferUdp | DeviceModes.NoCaptureLocal, read_timeout: readTimeoutMilliseconds);

@kayoub5
Copy link
Collaborator

kayoub5 commented Apr 2, 2021

@Terry550 how did you create the pcap writer, and did you create it before or after opening the device?

@Terry550
Copy link
Author

Terry550 commented Apr 2, 2021 via email

@kayoub5
Copy link
Collaborator

kayoub5 commented Apr 2, 2021

that would be the issue, you did not provide the link layer argument to the writer, so it's using ethernet link layer by default

@Terry550
Copy link
Author

Terry550 commented Apr 2, 2021 via email

@kayoub5
Copy link
Collaborator

kayoub5 commented Apr 2, 2021

The link layer is device dependent, see LinkLayer property of the device.

For npcap loopback it is null.

@Terry550
Copy link
Author

Terry550 commented Apr 2, 2021 via email

@kayoub5
Copy link
Collaborator

kayoub5 commented Apr 2, 2021

In a normal pcap file, you can't mix multiple link layers, it's a file format restriction, not a writer restriction.
however, pcapng files can do it.
for pcap some special link layers like ppp can be used as wrapper for other link layers.

@chmorgan
Copy link
Collaborator

chmorgan commented Apr 3, 2021 via email

@kayoub5
Copy link
Collaborator

kayoub5 commented Apr 3, 2021

Ironically, libpcap support for PCAPNG is extremely limited:

@Terry550
Copy link
Author

Terry550 commented Apr 3, 2021 via email

@kayoub5
Copy link
Collaborator

kayoub5 commented Apr 3, 2021

@chmorgan both this issue and #174 originate from the fact that the writer does not check that the packet link layer and the file link layer matches, maybe we should add a check and make it throw to avoid any confusion?

@chmorgan
Copy link
Collaborator

chmorgan commented Apr 3, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants