Mercurial > hg > octave-kai > gnulib-hg
changeset 15633:c2c292001fc0
inet_ntop: Support for MSVC on Windows Vista or newer.
* lib/arpa_inet.in.h (inet_ntop): Also consider REPLACE_INET_NTOP.
* lib/inet_ntop.c (rpl_inet_ntop): Use a simple wrapper if
HAVE_DECL_INET_NTOP is defined.
* m4/inet_ntop.m4 (gl_FUNC_INET_NTOP): Invoke gl_PREREQ_SYS_H_WINSOCK2.
On platforms with <winsock2.h>, test whether inet_ntop is declared in
<ws2tcpip.h>. If so, arrange to replace it.
* m4/arpa_inet_h.m4 (gl_ARPA_INET_H_DEFAULTS): Initialize
REPLACE_INET_NTOP.
* modules/arpa_inet (Makefile.am): Substitute REPLACE_INET_NTOP.
* modules/inet_ntop (Files): Add m4/sys_socket_h.m4.
(Depends-on, configure.ac): Update condition.
* doc/posix-functions/inet_ntop.texi: Mention the MSVC problem.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 17 Sep 2011 14:56:11 +0200 |
parents | c96b3b10e579 |
children | bcecbef40a05 |
files | ChangeLog doc/posix-functions/inet_ntop.texi lib/arpa_inet.in.h lib/inet_ntop.c m4/arpa_inet_h.m4 m4/inet_ntop.m4 modules/arpa_inet modules/inet_ntop |
diffstat | 8 files changed, 114 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-09-17 Bruno Haible <bruno@clisp.org> + + inet_ntop: Support for MSVC on Windows Vista or newer. + * lib/arpa_inet.in.h (inet_ntop): Also consider REPLACE_INET_NTOP. + * lib/inet_ntop.c (rpl_inet_ntop): Use a simple wrapper if + HAVE_DECL_INET_NTOP is defined. + * m4/inet_ntop.m4 (gl_FUNC_INET_NTOP): Invoke gl_PREREQ_SYS_H_WINSOCK2. + On platforms with <winsock2.h>, test whether inet_ntop is declared in + <ws2tcpip.h>. If so, arrange to replace it. + * m4/arpa_inet_h.m4 (gl_ARPA_INET_H_DEFAULTS): Initialize + REPLACE_INET_NTOP. + * modules/arpa_inet (Makefile.am): Substitute REPLACE_INET_NTOP. + * modules/inet_ntop (Files): Add m4/sys_socket_h.m4. + (Depends-on, configure.ac): Update condition. + * doc/posix-functions/inet_ntop.texi: Mention the MSVC problem. + 2011-09-16 Eric Blake <eblake@redhat.com> test-fsync: yet another enhancement
--- a/doc/posix-functions/inet_ntop.texi +++ b/doc/posix-functions/inet_ntop.texi @@ -15,6 +15,10 @@ This function is declared in @code{<netdb.h>} instead of @code{<arpa/inet.h>} on some platforms: NonStop Kernel. +@item +This function is declared in @code{<ws2tcpip.h>}, with a POSIX incompatible +declaration, on some platforms: +MSVC 9 on Windows >= Vista. @end itemize Portability problems not fixed by Gnulib:
--- a/lib/arpa_inet.in.h +++ b/lib/arpa_inet.in.h @@ -58,7 +58,6 @@ #if @GNULIB_INET_NTOP@ -# if !@HAVE_DECL_INET_NTOP@ /* Converts an internet address from internal format to a printable, presentable format. AF is an internet address family, such as AF_INET or AF_INET6. @@ -74,16 +73,31 @@ For more details, see the POSIX:2001 specification <http://www.opengroup.org/susv3xsh/inet_ntop.html>. */ +# if @REPLACE_INET_NTOP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef inet_ntop +# define inet_ntop rpl_inet_ntop +# endif +_GL_FUNCDECL_RPL (inet_ntop, const char *, + (int af, const void *restrict src, + char *restrict dst, socklen_t cnt) + _GL_ARG_NONNULL ((2, 3))); +_GL_CXXALIAS_RPL (inet_ntop, const char *, + (int af, const void *restrict src, + char *restrict dst, socklen_t cnt)); +# else +# if !@HAVE_DECL_INET_NTOP@ _GL_FUNCDECL_SYS (inet_ntop, const char *, (int af, const void *restrict src, char *restrict dst, socklen_t cnt) _GL_ARG_NONNULL ((2, 3))); -# endif +# endif /* Need to cast, because on NonStop Kernel, the fourth parameter is size_t cnt. */ _GL_CXXALIAS_SYS_CAST (inet_ntop, const char *, (int af, const void *restrict src, char *restrict dst, socklen_t cnt)); +# endif _GL_CXXALIASWARN (inet_ntop); #elif defined GNULIB_POSIXCHECK # undef inet_ntop
--- a/lib/inet_ntop.c +++ b/lib/inet_ntop.c @@ -38,12 +38,25 @@ /* Specification. */ #include <arpa/inet.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> +#if HAVE_DECL_INET_NTOP + +# undef inet_ntop -#define NS_IN6ADDRSZ 16 -#define NS_INT16SZ 2 +const char * +rpl_inet_ntop (int af, const void *restrict src, + char *restrict dst, socklen_t cnt) +{ + return inet_ntop (af, src, dst, cnt); +} + +#else + +# include <stdio.h> +# include <string.h> +# include <errno.h> + +# define NS_IN6ADDRSZ 16 +# define NS_INT16SZ 2 /* * WARNING: Don't even consider trying to compile this on a system where @@ -52,9 +65,9 @@ typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1]; static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size); -#if HAVE_IPV6 +# if HAVE_IPV6 static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t size); -#endif +# endif /* char * @@ -71,15 +84,15 @@ { switch (af) { -#if HAVE_IPV4 +# if HAVE_IPV4 case AF_INET: return (inet_ntop4 (src, dst, cnt)); -#endif +# endif -#if HAVE_IPV6 +# if HAVE_IPV6 case AF_INET6: return (inet_ntop6 (src, dst, cnt)); -#endif +# endif default: errno = EAFNOSUPPORT; @@ -118,7 +131,7 @@ return strcpy (dst, tmp); } -#if HAVE_IPV6 +# if HAVE_IPV6 /* const char * * inet_ntop6(src, dst, size) @@ -231,4 +244,6 @@ return strcpy (dst, tmp); } +# endif + #endif
--- a/m4/arpa_inet_h.m4 +++ b/m4/arpa_inet_h.m4 @@ -1,4 +1,4 @@ -# arpa_inet_h.m4 serial 12 +# arpa_inet_h.m4 serial 13 dnl Copyright (C) 2006, 2008-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -52,4 +52,5 @@ dnl Assume proper GNU behavior unless another module says otherwise. HAVE_DECL_INET_NTOP=1; AC_SUBST([HAVE_DECL_INET_NTOP]) HAVE_DECL_INET_PTON=1; AC_SUBST([HAVE_DECL_INET_PTON]) + REPLACE_INET_NTOP=0; AC_SUBST([REPLACE_INET_NTOP]) ])
--- a/m4/inet_ntop.m4 +++ b/m4/inet_ntop.m4 @@ -1,4 +1,4 @@ -# inet_ntop.m4 serial 16 +# inet_ntop.m4 serial 17 dnl Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,36 +9,54 @@ dnl Persuade Solaris <arpa/inet.h> to declare inet_ntop. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_REQUIRE([AC_C_RESTRICT]) + dnl Most platforms that provide inet_ntop define it in libc. dnl Solaris 8..10 provide inet_ntop in libnsl instead. + dnl Native Windows provides it in -lws2_32 instead, with a declaration in + dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl + dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it). HAVE_INET_NTOP=1 - gl_save_LIBS=$LIBS - AC_SEARCH_LIBS([inet_ntop], [nsl], [], - [AC_CHECK_FUNCS([inet_ntop]) - if test $ac_cv_func_inet_ntop = no; then - HAVE_INET_NTOP=0 - fi - ]) - LIBS=$gl_save_LIBS + INET_NTOP_LIB= + gl_PREREQ_SYS_H_WINSOCK2 + if test $HAVE_WINSOCK2_H = 1; then + AC_CHECK_DECLS([inet_ntop],,, [[#include <ws2tcpip.h>]]) + if test $ac_cv_have_decl_inet_ntop = yes; then + dnl It needs to be overridden, because the stdcall calling convention + dnl is not compliant with POSIX. + REPLACE_INET_NTOP=1 + INET_NTOP_LIB="-lws2_32" + else + HAVE_DECL_INET_NTOP=0 + HAVE_INET_NTOP=0 + fi + else + gl_save_LIBS=$LIBS + AC_SEARCH_LIBS([inet_ntop], [nsl], [], + [AC_CHECK_FUNCS([inet_ntop]) + if test $ac_cv_func_inet_ntop = no; then + HAVE_INET_NTOP=0 + fi + ]) + LIBS=$gl_save_LIBS - INET_NTOP_LIB= - if test "$ac_cv_search_inet_ntop" != "no" && - test "$ac_cv_search_inet_ntop" != "none required"; then - INET_NTOP_LIB="$ac_cv_search_inet_ntop" + if test "$ac_cv_search_inet_ntop" != "no" \ + && test "$ac_cv_search_inet_ntop" != "none required"; then + INET_NTOP_LIB="$ac_cv_search_inet_ntop" + fi + + AC_CHECK_HEADERS_ONCE([netdb.h]) + AC_CHECK_DECLS([inet_ntop],,, + [[#include <arpa/inet.h> + #if HAVE_NETDB_H + # include <netdb.h> + #endif + ]]) + if test $ac_cv_have_decl_inet_ntop = no; then + HAVE_DECL_INET_NTOP=0 + fi fi AC_SUBST([INET_NTOP_LIB]) - - AC_CHECK_HEADERS_ONCE([netdb.h]) - AC_CHECK_DECLS([inet_ntop],,, - [[#include <arpa/inet.h> - #if HAVE_NETDB_H - # include <netdb.h> - #endif - ]]) - if test $ac_cv_have_decl_inet_ntop = no; then - HAVE_DECL_INET_NTOP=0 - AC_REQUIRE([AC_C_RESTRICT]) - fi ]) # Prerequisites of lib/inet_ntop.c.
--- a/modules/arpa_inet +++ b/modules/arpa_inet @@ -36,6 +36,7 @@ -e 's/@''GNULIB_INET_PTON''@/$(GNULIB_INET_PTON)/g' \ -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \ -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \ + -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
--- a/modules/inet_ntop +++ b/modules/inet_ntop @@ -4,17 +4,18 @@ Files: lib/inet_ntop.c m4/inet_ntop.m4 +m4/sys_socket_h.m4 Depends-on: arpa_inet extensions -sys_socket [test $HAVE_INET_NTOP = 0] -errno [test $HAVE_INET_NTOP = 0] -netinet_in [test $HAVE_INET_NTOP = 0] +sys_socket [test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1] +errno [test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1] +netinet_in [test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1] configure.ac: gl_FUNC_INET_NTOP -if test $HAVE_INET_NTOP = 0; then +if test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1; then AC_LIBOBJ([inet_ntop]) gl_PREREQ_INET_NTOP fi