mirror of
https://github.com/nmap/nmap.git
synced 2025-12-08 21:51:28 +00:00
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.)
This commit is contained in:
6
tcpip.cc
6
tcpip.cc
@@ -2798,6 +2798,7 @@ int ipaddr2devname(char *dev, const struct in_addr *addr) {
|
|||||||
|
|
||||||
int devname2ipaddr(char *dev, struct in_addr *addr) {
|
int devname2ipaddr(char *dev, struct in_addr *addr) {
|
||||||
struct interface_info *mydevs;
|
struct interface_info *mydevs;
|
||||||
|
struct sockaddr_in *s;
|
||||||
int numdevs;
|
int numdevs;
|
||||||
int i;
|
int i;
|
||||||
mydevs = getinterfaces(&numdevs);
|
mydevs = getinterfaces(&numdevs);
|
||||||
@@ -2805,8 +2806,11 @@ mydevs = getinterfaces(&numdevs);
|
|||||||
if (!mydevs) return -1;
|
if (!mydevs) return -1;
|
||||||
|
|
||||||
for(i=0; i < numdevs; i++) {
|
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)) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user