Hi Simon, I propose these 6 patches to the recent getaddrinfo module changes:
- In getaddrinfo.h, fix an URL. - Fix the recognition of the Win32 platform. Some compilers (Borland C) set __WIN32__, not _WIN32. I use a shortcut 'WIN32_NATIVE'; 'WIN32' is already taken: it's sometimes defined by Cygwin. Also, maybe you want to exclude Cygwin from this code, because Cygwin already has full POSIX sockets. Cf. http://lists.gnu.org/archive/html/bug-gnulib/2006-05/msg00070.html - Order the three function pointers in the same order as the rest of the code. - Make the use_win32_p function static. There's no other code outside using it, right? - Change the parsing of a service name to reject empty strings and strings starting with spaces; this is would be an unnecessary extension to POSIX. In other words, expect the service name string to start with a digit. Also, reject ports > 65535. (Aren't ports limited to 65535 on every platform?) - Avoid redundant casts: Even with the stricter C++ cast rules, you don't need to cast from X* to void* or const void *. Bruno diff -r -c3 --exclude=CVS gnulib-20060614-modified/lib/getaddrinfo.h gnulib-20060628-modified/lib/getaddrinfo.h *** gnulib-20060614-modified/lib/getaddrinfo.h 2006-06-29 01:30:47.000000000 +0200 --- gnulib-20060628-modified/lib/getaddrinfo.h 2006-06-29 00:54:43.000000000 +0200 *************** *** 134,140 **** # if !HAVE_DECL_GETNAMEINFO /* Convert socket address to printable node and service names. For more details, see the POSIX:2001 specification ! <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */ extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, --- 134,140 ---- # if !HAVE_DECL_GETNAMEINFO /* Convert socket address to printable node and service names. For more details, see the POSIX:2001 specification ! <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */ extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, diff -r -c3 --exclude=CVS gnulib-20060614-modified/lib/getaddrinfo.c gnulib-20060628-modified/lib/getaddrinfo.c *** gnulib-20060614-modified/lib/getaddrinfo.c 2006-06-29 01:30:47.000000000 +0200 --- gnulib-20060628-modified/lib/getaddrinfo.c 2006-06-29 01:12:43.000000000 +0200 *************** *** 40,50 **** #include "strdup.h" ! #ifdef _WIN32 ! typedef void WSAAPI (*freeaddrinfo_func) (struct addrinfo*); typedef int WSAAPI (*getaddrinfo_func) (const char*, const char*, const struct addrinfo*, struct addrinfo**); typedef int WSAAPI (*getnameinfo_func) (const struct sockaddr*, socklen_t, char*, DWORD, char*, DWORD, int); --- 40,54 ---- #include "strdup.h" ! #if defined _WIN32 || defined __WIN32__ ! # define WIN32_NATIVE ! #endif ! ! #ifdef WIN32_NATIVE typedef int WSAAPI (*getaddrinfo_func) (const char*, const char*, const struct addrinfo*, struct addrinfo**); + typedef void WSAAPI (*freeaddrinfo_func) (struct addrinfo*); typedef int WSAAPI (*getnameinfo_func) (const struct sockaddr*, socklen_t, char*, DWORD, char*, DWORD, int); *************** *** 53,59 **** static freeaddrinfo_func freeaddrinfo_ptr = NULL; static getnameinfo_func getnameinfo_ptr = NULL; ! int use_win32_p (void) { static int done = 0; HMODULE h; --- 57,64 ---- static freeaddrinfo_func freeaddrinfo_ptr = NULL; static getnameinfo_func getnameinfo_ptr = NULL; ! static int ! use_win32_p (void) { static int done = 0; HMODULE h; *************** *** 128,134 **** }; #endif ! #ifdef _WIN32 if (use_win32_p ()) return getaddrinfo_ptr (nodename, servname, hints, res); #endif --- 133,139 ---- }; #endif ! #ifdef WIN32_NATIVE if (use_win32_p ()) return getaddrinfo_ptr (nodename, servname, hints, res); #endif *************** *** 162,169 **** if (!se) { char *c; port = strtoul (servname, &c, 10); ! if (*c) return EAI_NONAME; port = htons (port); } --- 167,176 ---- if (!se) { char *c; + if (!(*servname >= '0' && *servname <= '9)) + return EAI_NONAME; port = strtoul (servname, &c, 10); ! if (*c || port > 0xffff) return EAI_NONAME; port = htons (port); } *************** *** 285,291 **** void freeaddrinfo (struct addrinfo *ai) { ! #ifdef _WIN32 if (use_win32_p ()) return freeaddrinfo_ptr (ai); #endif --- 292,298 ---- void freeaddrinfo (struct addrinfo *ai) { ! #ifdef WIN32_NATIVE if (use_win32_p ()) return freeaddrinfo_ptr (ai); #endif *************** *** 307,313 **** char *restrict service, socklen_t servicelen, int flags) { ! #if _WIN32 if (use_win32_p ()) return getnameinfo_ptr (sa, salen, node, nodelen, service, servicelen, flags); --- 314,320 ---- char *restrict service, socklen_t servicelen, int flags) { ! #if WIN32_NATIVE if (use_win32_p ()) return getnameinfo_ptr (sa, salen, node, nodelen, service, servicelen, flags); *************** *** 347,353 **** #if HAVE_IPV4 case AF_INET: if (!inet_ntop (AF_INET, - (const void *) &(((const struct sockaddr_in *) sa)->sin_addr), node, nodelen)) return EAI_SYSTEM; --- 354,359 ---- *************** *** 357,363 **** #if HAVE_IPV6 case AF_INET6: if (!inet_ntop (AF_INET6, - (const void *) &(((const struct sockaddr_in6 *) sa)->sin6_addr), node, nodelen)) return EAI_SYSTEM; --- 363,368 ----