mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 07:31:33 +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:
@@ -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);
|
pcap_freealldevs(pcapdevs);
|
||||||
if (pname[0]) {
|
if (pname[0]) {
|
||||||
strlcpy(pcapdev, pname, pcapdevlen);
|
strlcpy(pcapdev, pname, pcapdevlen);
|
||||||
|
|||||||
Reference in New Issue
Block a user