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

How to associate pcap.Interface with net.Interface? #456

Open
irfabid opened this issue May 20, 2018 · 10 comments
Open

How to associate pcap.Interface with net.Interface? #456

irfabid opened this issue May 20, 2018 · 10 comments

Comments

@irfabid
Copy link
Contributor

irfabid commented May 20, 2018

Hi,

As mentioned in subject, I am trying to figure out which pcap.Interface represents which net.Interface

As I understand pcap.Interface is actually a hardware device, while net.Interface is a network connection (ie. a logical construct in Windows to control hardware device).

Is the only way to associate them together using IP Address? (suprisingly, pcap.Interface doesn't expose Hardware Address field)

I am looking for a better way to associate them together. Perhaps based on interface index? (couldn't find it in pcap.Interface)

@irfabid
Copy link
Contributor Author

irfabid commented May 23, 2018

Looking at source code of pcap.go, I saw that Handle has an unexported deviceIndex field. Can we export it but keep it read-only? (i.e. a method on *Handle which returns deviceIndex)

@gconnell any thoughts?

@gconnell
Copy link
Collaborator

I think just changing it deviceIndex -> DeviceIndex should be fine. Hopefully it actually matches with the net.Interface indexes :-/

@irfabid
Copy link
Contributor Author

irfabid commented May 28, 2018

It doesn't. At least not on Windows. I believe, it will never match on Windows with current code. That is because net.Interface refers to network connections and pcap.Interface refers to NIC. Their names are always different and current code tries to match them based on name.

I will test on Linux to get a complete picture, and then we will see how we can solve this.

@gconnell
Copy link
Collaborator

gconnell commented May 29, 2018 via email

@extrame
Copy link

extrame commented Mar 7, 2019

hello, any update on this issue? I am face the same problem in project... @gconnell @irfabid

@akkuman
Copy link

akkuman commented Jul 9, 2019

use pcap.FindAllDevs() can get the name which contains "Device\NPF_"

@ChenYahui2019
Copy link

use pcap.FindAllDevs() can get the name which contains "Device\NPF_"

The bug is about deviceIndex rather than name.

@Insolent-M1nx
Copy link

Any updates to this? Having the same issue with Windows devices.

@codeyourweb
Copy link

codeyourweb commented Jan 3, 2021

I had the same problem. I solved it by matching the IP addresses of the interfaces with those of the devices. It is certainly not the most elegant solution, but it works.

Here is an implementation of this solution in the arpscan.go:
https://github.com/codeyourweb/gopacket/blob/master/examples/arpscan/arpscan.go

@lylest
Copy link

lylest commented Mar 18, 2024

Facing same problem here i think window have not properly handled it

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

8 participants