Nmap Development mailing list archives

Re: MinGW patch, getaddrinfo


From: David Fifield <david () bamsoftware com>
Date: Wed, 3 Sep 2008 13:15:39 -0600

On Sat, Aug 30, 2008 at 11:23:43PM +0200, Gisle Vanem wrote:
That works fine, but another patch broke MingW. Patch:

--- SVN-Latest\nbase\nbase_winunix.h    Sat Aug 30 20:06:34 2008
+++ nbase\nbase_winunix.h     Sat Aug 30 20:23:08 2008
@@ -121,7 +121,9 @@
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h> /* IPv6 stuff */
+#ifdef _MSC_VER
#include <wspiapi.h> /* Necessary for getaddrinfo before Windows XP. */
+#endif
#include <time.h>
#include <iptypes.h>
#include <stdlib.h>

(MingW doesn't have <wspiapi.h>). 

It looks good. Is _MSC_VER the most reliable way to check for the
existence of the header? I ask only because I found
http://www.tremfusion.net/trac/changeset/443 which uses __MINGW32__ to
do the same thing.

I attached nbase-wspiapi-mingw.diff that does what you ask in a
different fashion, defining HAVE_WSPIAPI_H based on the value of
_MSC_VER. Please try it and if it works I'll apply it.

Another patch I would like to add is:

--- SVN-Latest\TargetGroup.cc   Sat Jul 26 15:27:43 2008
+++ TargetGroup.cc    Sat Aug 30 20:29:37 2008
@@ -299,7 +299,7 @@
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_INET6;
    rc = getaddrinfo(hostexp, NULL, &hints, &result);
-    if (rc != 0) {
+    if (rc != 0 || !result) {
      error("Failed to resolve given IPv6 hostname/IP: %s.  Note that you can't use '/mask' or '
[1-4,7,100-]' style ranges for IPv6.  Error code %d: %s", hostexp, rc, gai_strerror(rc));
      free(hostexp);
      if (result) freeaddrinfo(result);

-------------

On my Win-XP (sp3) box, I don't have IPv6 installed. But IPv6 lookups works just the
same (windns.dll is independant of IPv6 it seems). So, for some 
strange reason getaddrinfo() returns with 'rc==0', but 
'result==NULL'. Better safe that sorry. Hence the extra test.

That makes sense. I'll apply the patch but I have a few questions first.
Is this patch necessary for all targets, or only those that have IPv6
addresses? Or is there some other condition that causes the result to be
NULL?

I see two other places where getaddrinfo is used, so I'm curious why
only this one needs to be patched. What happens when you run

nmap -6 -S ::1 localhost

And what happens when you script scan one of the targets that requires
the above patch? There is a call to getaddrinfo in nse_nsock too.

David Fifield

Attachment: nbase-wspiapi-mingw.diff
Description:


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

Current thread: