From 817fdad2d50681e17f336757edd762c8e497be9a Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 29 Nov 2015 17:30:33 -0700 Subject: [PATCH] Windows with MinGW: Fix network address resolution Use the same code as for MSVC compilation, which is as simple as defining `HAVE_GETADDRINFO`. Closes PR 15192 --- racket/src/racket/src/network.c | 43 +++++---------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/racket/src/racket/src/network.c b/racket/src/racket/src/network.c index 10af061f5b..76a42abdf8 100644 --- a/racket/src/racket/src/network.c +++ b/racket/src/racket/src/network.c @@ -398,6 +398,12 @@ SHARED_OK static struct protoent *proto; /* mz_addrinfo is defined in scheme.h */ +#if defined(__MINGW32__) && !defined(HAVE_GETADDRINFO) +/* Although `configure` didn't discover it, we do have getaddrinfo() + from Winsock */ +# define HAVE_GETADDRINFO +#endif + #ifdef HAVE_GETADDRINFO # define mzAI_PASSIVE AI_PASSIVE # define mz_getaddrinfo getaddrinfo @@ -411,24 +417,6 @@ static int mz_getaddrinfo(const char *nodename, const char *servname, { struct hostent *h; -#ifdef __MINGW32__ - { - HMODULE hm; - hm = LoadLibrary("ws2_32.dll"); - if (hm) { - gai_t gai; - gai = (gai_t)GetProcAddress(hm, "getaddrinfo"); - if (gai) { - int v; - v = gai(nodename, servname, hints, res); - if (!v && !(*res)->ai_addr) - (*res)->ai_addrlen = 0; - return v; - } - } - } -#endif - if (nodename) h = gethostbyname(nodename); else @@ -471,32 +459,13 @@ static int mz_getaddrinfo(const char *nodename, const char *servname, void mz_freeaddrinfo(struct mz_addrinfo *ai) XFORM_SKIP_PROC { -#ifdef __MINGW32__ - { - HMODULE hm; - hm = LoadLibrary("ws2_32.dll"); - if (hm) { - fai_t fai; - fai = (fai_t)GetProcAddress(hm, "freeaddrinfo"); - if (fai) { - fai(ai); - return; - } - } - } -#endif - free(ai->ai_addr); free(ai); } const char *mz_gai_strerror(int ecode) XFORM_SKIP_PROC { -#ifdef __MINGW32__ - return NULL; /* => use FormatMessageW(), instead */ -#else return hstrerror(ecode); -#endif } #endif