From 0101e9e0ab45ebb8a99e40492a0938b74ac39f5e Mon Sep 17 00:00:00 2001 From: david Date: Thu, 12 Jun 2008 00:57:49 +0000 Subject: [PATCH] Change the DEV/WINDEVICE output (the part that shows the mapping from dnet names to WinPcap names) to use the no-nonsense approach of simply calling DnetName2PcapName for every interface returned by getinterfaces. DnetName2PcapName calls intf_get_pcap_devname, which is same function called by eth_open on Windows, so now the output really reflects Nmap's view of the world. This doesn't remove interface aliases, so if you have any aliases enabled, you will see what look like duplicated lines. I have chosen to leave them in for now to assist with debugging if any alias-related problems come up in the future. They could be taken out easily if this is not desired. This brings what may be a startling change: the lo0 loopback interface no longer maps to /Device/NPF_GenericDialupAdapter, but to no adapter at all (signified by ""). I believe the old behavior was wrong, merely an artifact of the way the code happened to line up two lists of interfaces. /Device/NFP_GenericDialupAdapter is for dialup and VPN capture, and the loopback interface isn't supported by WinPcap (or Windows for that matter) at all. See http://www.winpcap.org/misc/faq.htm#Q-5 http://www.winpcap.org/misc/faq.htm#Q-13 --- output.cc | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/output.cc b/output.cc index ee3cd68c7..30f133802 100644 --- a/output.cc +++ b/output.cc @@ -292,6 +292,9 @@ static int getServiceXMLBuf(struct serviceDeductions *sd, char *xmlbuf, return 0; } +/* From tcpip.cc. */ +bool DnetName2PcapName(const char *dnetdev, char *pcapdev, int pcapdevlen); + /* Print a detailed list of Nmap interfaces and routes to normal/skiddy/stdout output */ int print_iflist(void) { @@ -335,31 +338,27 @@ int print_iflist(void) { delete Tbl; } - /* Display windows device names */ - if((p_ifaces = getpcapinterfaces()) != NULL && numifs > 0) { - Tbl = new NmapOutputTable(numifs+1, 2); - Tbl->addItem(0, 0, false, "DEV"); - Tbl->addItem(0, 1, false, "WINDEVICE"); - i = numifs; - { - //the previous interface that we printed to screen - char * lastface=""; - //Now print off all the interfaces, we check to make sure we dont print any duplicate interfaces. - //In the case of an interface alias, iflist will have a double entry but p_iface_iter - //will only have one. So we check to make sure we only print out one copy of each hardware interface. - for(p_iface_iter = p_ifaces; p_iface_iter != NULL && i >= 1; i--) { - if(strcmp(lastface,iflist[i-1].devname)!=0){ - Tbl->addItem(i, 0, false, iflist[i-1].devname); - Tbl->addItem(i, 1, false, p_iface_iter->name); - p_iface_iter = p_iface_iter->next; - lastface = iflist[i-1].devname; - } - } - } - log_write(LOG_PLAIN, "%s\n", Tbl->printableTable(NULL)); + if (numifs > 0) { + /* Display the mapping from libdnet interface names (like "eth0") to + WinPcap interface names (like "\Device\NPF_{...}"). This is the same + mapping used by eth_open and so can help diagnose connection problems. */ + NmapOutputTable Tbl(numifs + 1, 2); + + Tbl.addItem(0, 0, false, "DEV"); + Tbl.addItem(0, 1, false, "WINDEVICE"); + + for (i = 0; i < numifs; i++) { + char pcap_name[1024]; + + if (!DnetName2PcapName(iflist[i].devname, pcap_name, sizeof(pcap_name))) + Strncpy(pcap_name, "", sizeof(pcap_name)); + + Tbl.addItem(i + 1, 0, false, iflist[i].devname); + Tbl.addItem(i + 1, 1, true, pcap_name); + } + + log_write(LOG_PLAIN, "%s\n", Tbl.printableTable(NULL)); log_flush_all(); - delete Tbl; - pcap_freealldevs(p_ifaces); } /* OK -- time to handle routes */