Nmap Development mailing list archives

Re: [BUG] add_dns_server() adds bogus IPv4 nameserver address


From: David Fifield <david () bamsoftware com>
Date: Wed, 13 Jan 2010 18:20:34 -0700

On Wed, Jan 13, 2010 at 11:19:17PM +0000, jah wrote:
It wasn't after all, getaddrinfo() that was the problem.  After a lot of
head scratching, I had a look at my nmap-exp branch where I began work
(a long time ago) on ipv6 support for mass_dns.  I found that the
current code in get_dns_servers() uses inet_ntop() to convert a
sockaddr_storage to a string, whereas in my exp branch I'd used
inet_socktop().
inet_socktop() works like a charm.  I'm not exactly sure what's wrong
with using inet_ntop() (or whether it's just called incorrectly in this
case), but is there any reason not to use inet_socktop()?

If not, I'll check in the attached.

Regards,

jah

--- nmap_dns.cc.orig  2010-01-13 23:16:26.390625000 +0000
+++ nmap_dns.cc       2010-01-13 23:04:00.812500000 +0000
@@ -1345,7 +1345,6 @@
 // Returns a list of known DNS servers
 std::list<std::string> get_dns_servers() {
   init_servs();
-  char addrStr[INET6_ADDRSTRLEN];
 
   // If the user said --system-dns (!o.mass_dns), we should never return a list
   // of servers.
@@ -1354,8 +1353,7 @@
   std::list<dns_server *>::iterator servI;
   std::list<std::string> serverList;
   for(servI = servs.begin(); servI != servs.end(); servI++) {
-    inet_ntop((*servI)->addr.ss_family, (&(*servI)->addr),addrStr, sizeof(addrStr));  
-    serverList.push_back(addrStr);
+    serverList.push_back(inet_socktop((struct sockaddr_storage *) &(*servI)->addr));
   }
   return serverList;
 }

That looks good, please commit it. The original code, from r16016, was
incorrect. It was giving the address of the beginning of the
sockaddr_storage structure when it should have been giving the address
of the sin_addr or sin6_addr member as appropriate.

Boy, there are a lot of ways to get a printable address in Nmap.
inet_ntoa, inet_ntop, inet_socktop, inet_ntop_both, inet_ntop_ez, and
getnameinfo are some that I can find. Ncat also has its own inet_socktop
and a getnameinfo wrapper called address_to_string. If someone wants a
nice easy project to do, seeing how many of these functions can be
removed and replaced with others would be good.

David Fifield
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: