summaryrefslogtreecommitdiff
path: root/lib/inet_ntop.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-09-17 14:56:11 +0200
committerBruno Haible <bruno@clisp.org>2011-09-17 14:56:11 +0200
commit91d0cb58387e1e52b7023bcd0b01c1337c0fb9c8 (patch)
tree317dc512088c5a3a5bc973f6964b0aa092057364 /lib/inet_ntop.c
parentabd89efaeb4366d99ad6407c415bce8d6bafb316 (diff)
downloadgnulib-91d0cb58387e1e52b7023bcd0b01c1337c0fb9c8.tar.gz
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.
Diffstat (limited to 'lib/inet_ntop.c')
-rw-r--r--lib/inet_ntop.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c
index 5602a29e7f..6b801747b0 100644
--- 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
-#define NS_IN6ADDRSZ 16
-#define NS_INT16SZ 2
+# undef inet_ntop
+
+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 @@ inet_ntop (int af, const void *restrict src,
{
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 @@ inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
return strcpy (dst, tmp);
}
-#if HAVE_IPV6
+# if HAVE_IPV6
/* const char *
* inet_ntop6(src, dst, size)
@@ -231,4 +244,6 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
return strcpy (dst, tmp);
}
+# endif
+
#endif