> But the internal gnulib implementation might change, right? I mean, the > FD_TO_SOCKET macro is an implementation detail in gnulib, but if that > ever changes, it would break binary compatibility if GnuTLS exposes the > SOCKET vs int difference.
No, there's no other sensible way. The macro is there (instead of using _get_osfhandle directly) because the code on which I based lib/winsock.c was wrapping all socket functions, independent of whether Mingw was the underlying runtime. For the record, the reason for that was to work around the presence or lack of the sa_len member of struct sockaddr. That's another wart that gnulib could work around; but it's only important for Unix sockets if applications only use getaddrinfo to build socket addresses. BTW, are there platforms with sa_len (typically BSD systems) and without getaddrinfo? If so, something like this would be needed: diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 06501f2..e4ed821 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -301,6 +301,22 @@ getaddrinfo (const char *restrict nodename, tmp->ai_addr->sa_family = he->h_addrtype; tmp->ai_family = he->h_addrtype; +#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN + switch (he->h_addrtype) + { +#if HAVE_IPV4 + case AF_INET: + tmp->ai_addr->sa_len = sizeof (struct sockaddr_in); + break; +#endif +#if HAVE_IPV6 + case AF_INET6: + tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6); + break; +#endif + } +#endif + /* FIXME: If more than one address, create linked list of addrinfo's. */ *res = tmp; diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4 index 5d36c19..52135ba 100644 --- a/m4/getaddrinfo.m4 +++ b/m4/getaddrinfo.m4 @@ -99,6 +99,12 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO], [ AC_REQUIRE([gl_HEADER_SYS_SOCKET]) AC_REQUIRE([AC_C_INLINE]) AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + dnl Including sys/socket.h is wrong for Windows, but Windows does not + dnl have sa_len so the result is correct anyway. + AC_CHECK_MEMBERS([struct sockaddr.sa_len],,, + [#include <sys/socket.h>]) + AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h) AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[ /* sys/types.h is not needed according to POSIX, but the Paolo