In intf_get_pcap_devname, allow a match if only the hardware address

matches, but keep searching in case there's an interface where both the
hardware address and description string match.

Matching only on the hardware address is not sufficient, because several
interfaces will have the same address in the case of interface teaming.
See the log message for r17542.

But this revision broke interface matching for Luis MartinGarcia and Rob
Nicholls. For Luis, the call to PacketRequest with OID_GEN_FRIENDLY_NAME
was failing. For Rob, the friendly name differed slightly from the
description provided by libpcap. This change makes a hardware address
match good enough but will prefer a description match too.
This commit is contained in:
david 2010-07-14 16:44:59 +00:00
parent b39561622e
commit e108318cd2

View file

@ -396,7 +396,7 @@ intf_get_pcap_devname(const char *intf_name, char *pcapdev, int pcapdevlen)
{
wchar_t descr_wc[512];
pcap_if_t *pcapdevs;
pcap_if_t *pdev;
pcap_if_t *pdev, *selected;
intf_t *intf;
MIB_IFROW ifrow;
@ -424,6 +424,7 @@ intf_get_pcap_devname(const char *intf_name, char *pcapdev, int pcapdevlen)
its interface list from the registry; dnet gets it from GetIfList.
We must match them up using values common to both data sets. We do
it by comparing hardware addresses and interface descriptions. */
selected = NULL;
for (pdev = pcapdevs; pdev != NULL; pdev = pdev->next) {
PACKET_OID_DATA *data;
u_char buf[512];
@ -447,6 +448,11 @@ intf_get_pcap_devname(const char *intf_name, char *pcapdev, int pcapdevlen)
goto close_adapter;
}
/* A hardware address match is good enough, but we will prefer
an additional match with the description if available. */
if (selected == NULL)
selected = pdev;
/* Distinct interfaces can have the same MAC address in the
case of "teamed" interfaces. Additionally check the
description string. */
@ -457,7 +463,9 @@ intf_get_pcap_devname(const char *intf_name, char *pcapdev, int pcapdevlen)
if (wcscmp(descr_wc, (wchar_t *) data->Data) != 0)
goto close_adapter;
/* Found it. */
/* This matches both the hardware address and description, so
it's the best candidate. */
selected = pdev;
PacketCloseAdapter(lpa);
break;
@ -465,10 +473,10 @@ close_adapter:
PacketCloseAdapter(lpa);
}
if (pdev != NULL)
strlcpy(pcapdev, pdev->name, pcapdevlen);
if (selected != NULL)
strlcpy(pcapdev, selected->name, pcapdevlen);
pcap_freealldevs(pcapdevs);
if (pdev == NULL)
if (selected == NULL)
return -1;
else
return 0;