1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 22:21:29 +00:00

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.
This commit is contained in:
david
2008-06-20 20:57:40 +00:00
parent 09cc37f7f0
commit 38c50f3ac3

View File

@@ -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(&eth, &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);