From 2b4e4e7a8d607b285ba908126ffcd3a87cdacf36 Mon Sep 17 00:00:00 2001 From: luis Date: Tue, 7 Jul 2009 14:37:19 +0000 Subject: [PATCH] Fixed a bug in devname2ipaddr(). The IP returned by the function was always 2.0.0.0 due to an error handling a pointer. Check http://seclists.org/nmap-dev/2009/q3/0047.html for detailed information. Also, devname2ipaddr() now makes sure we are dealing with AF_INET devices (currently the getinterfaces() function already skips non AF_INET interfaces, but this way it won't break if that changes in the future.) --- tcpip.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tcpip.cc b/tcpip.cc index 8540d3870..2d5b7fefe 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -2798,6 +2798,7 @@ int ipaddr2devname(char *dev, const struct in_addr *addr) { int devname2ipaddr(char *dev, struct in_addr *addr) { struct interface_info *mydevs; +struct sockaddr_in *s; int numdevs; int i; mydevs = getinterfaces(&numdevs); @@ -2805,8 +2806,11 @@ mydevs = getinterfaces(&numdevs); if (!mydevs) return -1; for(i=0; i < numdevs; i++) { + s=(struct sockaddr_in *)&mydevs[i].addr; + if (s->sin_family!=AF_INET) /* Currently we only support IPv4 */ + continue; if (!strcmp(dev, mydevs[i].devfullname)) { - memcpy(addr, (char *) &mydevs[i].addr, sizeof(struct in_addr)); + memcpy(addr, (char *) &s->sin_addr, sizeof(struct in_addr)); return 0; } }