From 38c50f3ac36ca9a848ef7b5585e387fd823f8fc5 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 20 Jun 2008 20:57:40 +0000 Subject: [PATCH] In eth_get_pcap_devname (nee intf_get_pcap_devname), fall back on matching MAC addresses if matching IP addresses fails. I have a feeling this is more reliable than matching IP addresses, but as I'm not sure, I have made it the backup so that nothing will stop working that was working before. The MAC address matching works fine for me if I disable the IP address matching. The code is adapted from libdnet 1.11. --- libdnet-stripped/src/eth-win32.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libdnet-stripped/src/eth-win32.c b/libdnet-stripped/src/eth-win32.c index 7a1b9b9ce..1316e7211 100644 --- a/libdnet-stripped/src/eth-win32.c +++ b/libdnet-stripped/src/eth-win32.c @@ -179,6 +179,27 @@ int eth_get_pcap_devname(const char *ifname, char *pcapdev, int pcapdevlen) { } } + /* If matching IP addresses didn't work, try matching hardware + addresses. This is adapted from libdnet 1.11. */ + if (pname[0] == '\0' && ie.intf_link_addr.addr_type == ADDR_TYPE_ETH) { + for(pdev=pcapdevs; pdev && !pname[0]; pdev = pdev->next) { + eth_t eth; + eth_addr_t ea; + + eth.lpa = PacketOpenAdapter(pdev->name); + if (eth.lpa == NULL) + continue; + if (eth.lpa->hFile != INVALID_HANDLE_VALUE && + eth_get(ð, &ea) == 0 && + memcmp(&ea, &ie.intf_link_addr.addr_eth, + ETH_ADDR_LEN) == 0) { + /* Found it -- Yay! */ + strlcpy(pname, pdev->name, sizeof(pname)); + } + PacketCloseAdapter(eth.lpa); + } + } + pcap_freealldevs(pcapdevs); if (pname[0]) { strlcpy(pcapdev, pname, pcapdevlen);