From 450052603b0e5134642946d29262d34d9fbc0155 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 20 Jun 2008 19:44:13 +0000 Subject: [PATCH] In intf_get_pcap_devname, compare each of the pcap device's addresses against all of the dnet device's addresses, not just the first one. This is a long shot to fix the "dnet: Failed to open eth4" problem on Vista, but it's the right thing anyway. --- libdnet-stripped/src/intf-win32.c | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/libdnet-stripped/src/intf-win32.c b/libdnet-stripped/src/intf-win32.c index 3ffd4fac2..ea38e33c6 100644 --- a/libdnet-stripped/src/intf-win32.c +++ b/libdnet-stripped/src/intf-win32.c @@ -314,20 +314,6 @@ int intf_get_pcap_devname(const char *ifname, char *pcapdev, int pcapdevlen) { } intf_close(intf); - /* Find the first IPv4 address for ie */ - if (ie.intf_addr.addr_type == ADDR_TYPE_IP) { - addr_ntos(&ie.intf_addr, (struct sockaddr *) &devip); - } else { - for(i=0; i < (int) ie.intf_alias_num; i++) { - if (ie.intf_alias_addrs[i].addr_type == ADDR_TYPE_IP) { - addr_ntos(&ie.intf_alias_addrs[i], (struct sockaddr *) &devip); - break; - } - } - if (i == ie.intf_alias_num) - return -1; // Failed to find IPv4 address, which is currently a requirement - } - /* Next we must find the pcap device name corresponding to the device. The device description used to be compared with those from PacketGetAdapterNames(), but that was unrelaible because dnet and pcap sometimes give different descriptions. For example, @@ -343,10 +329,27 @@ int intf_get_pcap_devname(const char *ifname, char *pcapdev, int pcapdevlen) { for (pa=pdev->addresses; pa && !pname[0]; pa = pa->next) { if (pa->addr->sa_family != AF_INET) continue; - if (((struct sockaddr_in *)pa->addr)->sin_addr.s_addr == devip.sin_addr.s_addr) { - strlcpy(pname, pdev->name, sizeof(pname)); /* Found it -- Yay! */ - break; - } + + /* Match this address of pdev against all the addresses of ie. + i == -1 tests against the primary address of the interface. + i >= 0 tests against alias addresses. */ + for (i = -1; i < (int) ie.intf_alias_num; i++) { + if (i == -1) { + if (ie.intf_addr.addr_type != ADDR_TYPE_IP) + continue; + addr_ntos(&ie.intf_addr, (struct sockaddr *) &devip); + } else { + if (ie.intf_alias_addrs[i].addr_type != ADDR_TYPE_IP) + continue; + addr_ntos(&ie.intf_alias_addrs[i], (struct sockaddr *) &devip); + } + if (((struct sockaddr_in *)pa->addr)->sin_addr.s_addr == devip.sin_addr.s_addr) { + /* Found it -- Yay! */ + strlcpy(pname, pdev->name, sizeof(pname)); + /* Assigning pname[0] breaks out of the outer loops too. */ + break; + } + } } }