Oops, I've re-made a patch. Please give it a try.
Index: Socket6.xs
===================================================================
--- Socket6.xs (revision 639)
+++ Socket6.xs (working copy)
@@ -81,6 +81,10 @@
#include "config.h"
+#if defined(HAVE_INET_NTOP) && !defined(CAN_INET_NTOP)
+#undef HAVE_INET_NTOP
+#endif
+
#ifndef HAVE_GETADDRINFO
#include "getaddrinfo.c"
#define NI_MAXHOST 1025
@@ -540,7 +544,7 @@
addrlen, alen);
}
- Copy( address, &addr, sizeof addr, char );
+ Copy( address, &addr, alen, char );
addr_str[0] = 0;
inet_ntop(af, &addr, addr_str, sizeof addr_str);
Index: aclocal.m4
===================================================================
--- aclocal.m4 (revision 639)
+++ aclocal.m4 (working copy)
@@ -183,3 +183,34 @@
ifelse([$2], , :, [$2])
fi
AC_MSG_RESULT($ipv6_cv_socklen_t)])
+dnl
+dnl Check if darwin inet_ntop is broken
+AC_DEFUN([IPv6_CHECK_INET_NTOP], [
+AC_MSG_CHECKING(for working inet_ntop)
+AC_CACHE_VAL(ipv6_cv_can_inet_ntop, [dnl
+AC_RUN_IFELSE([AC_LANG_SOURCE[
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+int
+main() {
+ static struct in6_addr addr;
+ static char str[INET6_ADDRSTRLEN];
+
+ addr.s6_addr[15] = 0x21;
+ inet_ntop(AF_INET6, &addr, str, sizeof(str));
+ if (strcmp(str,"::21"))
+ exit(1);
+}
+]], [ipv6_cv_can_inet_ntop=yes], [ipv6_cv_can_inet_ntop=no])])dnl
+dnl
+if test $ipv6_cv_can_inet_ntop = yes; then
+ ifelse([$1], , AC_DEFINE(CAN_INET_NTOP,[1],[Do we have a working inet_ntop?]), [$1])
+else
+ ifelse([$2], , :, [$2])
+fi
+AC_MSG_RESULT($ipv6_cv_can_inet_ntop)])
Index: config.h.in
===================================================================
--- config.h.in (revision 639)
+++ config.h.in (working copy)
@@ -1,5 +1,8 @@
/* config.h.in. Generated from configure.in by autoheader. */
+/* Do we have a working inet_ntop? */
+#undef CAN_INET_NTOP
+
/* Define to 1 if you have the `getaddrinfo' function. */
#undef HAVE_GETADDRINFO
@@ -45,5 +48,8 @@
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
/* Define to the version of this package. */
#undef PACKAGE_VERSION
Index: configure.in
===================================================================
--- configure.in (revision 639)
+++ configure.in (working copy)
@@ -63,6 +63,7 @@
INET6LIBS="-L$ipv6_cv_dir/lib -linet6"
fi
+IPv6_CHECK_INET_NTOP()
IPv6_CHECK_SA_LEN()
IPv6_CHECK_SIN6_SCOPE_ID()
IPv6_CHECK_SOCKLEN_T()
Index: inet_ntop.c
===================================================================
--- inet_ntop.c (revision 639)
+++ inet_ntop.c (working copy)
@@ -24,6 +24,12 @@
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
+#ifdef HAVE_SOCKLEN_T
+#define SOCKLEN_T socklen_t
+#else
+#define SOCKLEN_T size_t
+#endif
+
static const char *inet_ntop4(const unsigned char *src, char *dst,
size_t size);
@@ -41,14 +47,14 @@
* Paul Vixie, 1996.
*/
const char *
-inet_ntop(int af, const void *src, char *dst, size_t size)
+inet_ntop(int af, const void *src, char *dst, SOCKLEN_T size)
{
switch (af) {
case AF_INET:
- return (inet_ntop4(src, dst, size));
+ return (inet_ntop4(src, dst, (size_t)size));
#ifdef AF_INET6
case AF_INET6:
- return (inet_ntop6(src, dst, size));
+ return (inet_ntop6(src, dst, (size_t)size));
#endif
default:
errno = EAFNOSUPPORT;
Index: t/use.t
===================================================================
--- t/use.t (revision 639)
+++ t/use.t (working copy)
@@ -31,8 +31,8 @@
use strict;
use Test;
-use Socket qw(AF_INET SOCK_STREAM);
-BEGIN { plan tests => 3 }
+use Socket qw(AF_INET AF_INET6 SOCK_STREAM);
+BEGIN { plan tests => 9 }
use Socket6; ok(1);
my @tmp = getaddrinfo("localhost", "", AF_INET, SOCK_STREAM, 0, 0);
@@ -44,5 +44,14 @@
if ($addr eq "127.0.0.1" && $port eq "0") {
ok(3);
}
-exit;
-__END__
+ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "::")), "::");
+
+# this fails under darwin
+ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "::21")), "::21")
+ or print "# ", unpack("H*", inet_pton(AF_INET6, "::21")), "\n";
+
+ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "43::")), "43::");
+ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "1:2:3:4:5:6:7::")),
+ "1:2:3:4:5:6:7:0");
+ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "1::8")), "1::8");
+ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "FF00::FFFF")), "ff00::ffff");