Skip Menu |

This queue is for tickets about the Socket6 CPAN distribution.

Report information
The Basics
Id: 113005
Status: resolved
Priority: 0/
Queue: Socket6

People
Owner: ume [...] mahoroba.org
Requestors: RURBAN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.26



Subject: system inet_ntop broken in darwin
The fallback code works fine. I've added some tests, which do fail on darwin, and work fine when undefining HAVE_INET_NTOP I'm adding a new configure probe to test for this upstream bug. Looks pretty scary to me when they cannot stringify a simple ipv6 address correctly. ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "::21")), "::21") # this fails under darwin or print "# ",unpack("H*", inet_pton(AF_INET6, "::21")),"\n"; ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "1:2:3:4:5:6:7::")), "1:2:3:4:5:6:7:0"); See https://rt.cpan.org/Ticket/Update.html?id=88635 where we detected it. -- Reini Urban
On Mon Mar 14 10:57:54 2016, RURBAN wrote: Show quoted text
> The fallback code works fine. > > I've added some tests, which do fail on darwin, and work fine when > undefining HAVE_INET_NTOP > I'm adding a new configure probe to test for this upstream bug. > Looks pretty scary to me when they cannot stringify a simple ipv6 > address correctly. > > ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "::21")), "::21") # this > fails under darwin > or print "# ",unpack("H*", inet_pton(AF_INET6, "::21")),"\n"; > ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "1:2:3:4:5:6:7::")), > "1:2:3:4:5:6:7:0"); > > See https://rt.cpan.org/Ticket/Update.html?id=88635 where we detected > it.
Attached are the patches to fix those, and one other issue. (plus a travis.yml) the darwin issue is fixed with the 3rd patch. -- Reini Urban
Subject: 0001-RT-54629-add-SOL_IPV6-constants.patch
From 7a750b073bc29f36423bcd62f94c829f1b579545 Mon Sep 17 00:00:00 2001 From: Reini Urban <rurban@cpanel.net> Date: Mon, 14 Mar 2016 12:26:32 +0100 Subject: [PATCH 1/3] RT #54629: add SOL_IPV6 constants patch by David Madore --- Socket6.pm | 19 +++++++++++ Socket6.xs | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git Socket6.pm Socket6.pm index e70258e..f06b210 100644 --- Socket6.pm +++ Socket6.pm @@ -260,6 +260,25 @@ use base qw(Exporter DynaLoader); IPV6_AUTH_NETWORK_LEVEL IPV6_ESP_NETWORK_LEVEL IPV6_ESP_TRANS_LEVEL + IPV6_ADDRFORM + IPV6_ADD_MEMBERSHIP + IPV6_DROP_MEMBERSHIP + IPV6_MTU + IPV6_MTU_DISCOVER + IPV6_MULTICAST_HOPS + IPV6_MULTICAST_IF + IPV6_MULTICAST_LOOP + IPV6_PKTINFO + IPV6_RTHDR + IPV6_AUTHHDR + IPV6_DSTOPS + IPV6_HOPOPTS + IPV6_FLOWINFO + IPV6_HOPLIMIT + IPV6_RECVERR + IPV6_ROUTER_ALERT + IPV6_UNICAST_HOPS + IPV6_V6ONLY NI_NOFQDN NI_NUMERICHOST NI_NAMEREQD diff --git Socket6.xs Socket6.xs index a877a10..900fa5f 100644 --- Socket6.xs +++ Socket6.xs @@ -368,6 +368,114 @@ constant(char *name, int arg) #else goto not_there; #endif + if (strEQ(name, "IPV6_ADDRFORM")) +#ifdef IPV6_ADDRFORM + return IPV6_ADDRFORM; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_DROP_MEMBERSHIP")) +#ifdef IPV6_DROP_MEMBERSHIP + return IPV6_DROP_MEMBERSHIP; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_MTU")) +#ifdef IPV6_MTU + return IPV6_MTU; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_MTU_DISCOVER")) +#ifdef IPV6_MTU_DISCOVER + return IPV6_MTU_DISCOVER; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_MULTICAST_HOPS")) +#ifdef IPV6_MULTICAST_HOPS + return IPV6_MULTICAST_HOPS; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_MULTICAST_IF")) +#ifdef IPV6_MULTICAST_IF + return IPV6_MULTICAST_IF; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_MULTICAST_LOOP")) +#ifdef IPV6_MULTICAST_LOOP + return IPV6_MULTICAST_LOOP; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_PKTINFO")) +#ifdef IPV6_PKTINFO + return IPV6_PKTINFO; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_RTHDR")) +#ifdef IPV6_RTHDR + return IPV6_RTHDR; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_AUTHHDR")) +#ifdef IPV6_AUTHHDR + return IPV6_AUTHHDR; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_DSTOPS")) +#ifdef IPV6_DSTOPS + return IPV6_DSTOPS; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_HOPOPTS")) +#ifdef IPV6_HOPOPTS + return IPV6_HOPOPTS; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_FLOWINFO")) +#ifdef IPV6_FLOWINFO + return IPV6_FLOWINFO; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_HOPLIMIT")) +#ifdef IPV6_HOPLIMIT + return IPV6_HOPLIMIT; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_RECVERR")) +#ifdef IPV6_RECVERR + return IPV6_RECVERR; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_ROUTER_ALERT")) +#ifdef IPV6_ROUTER_ALERT + return IPV6_ROUTER_ALERT; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_UNICAST_HOPS")) +#ifdef IPV6_UNICAST_HOPS + return IPV6_UNICAST_HOPS; +#else + goto not_there; +#endif + if (strEQ(name, "IPV6_V6ONLY")) +#ifdef IPV6_V6ONLY + return IPV6_V6ONLY; +#else + goto not_there; +#endif break; case 'N': if (strEQ(name, "NI_NOFQDN")) -- 2.7.2
Subject: 0002-add-.travis.yml.patch
From 2ec43656dfc0dcf6017b28f0fabbc03d6bea5041 Mon Sep 17 00:00:00 2001 From: Reini Urban <rurban@cpanel.net> Date: Mon, 14 Mar 2016 12:36:02 +0100 Subject: [PATCH 2/3] add .travis.yml --- .travis.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .travis.yml diff --git .travis.yml .travis.yml new file mode 100644 index 0000000..0ab0a07 --- /dev/null +++ .travis.yml @@ -0,0 +1,23 @@ +language: perl +sudo: false +os: + - linux +# - osx +# osx has still no perlbrew nor cpanm. which is bad, because darwin is buggy + +perl: + - '5.22' + - '5.20' + - '5.18' + - '5.16' + - '5.14' + - '5.12' + - '5.10' + +script: + - perl Makefile.PL && make && make test + +# Hack to not run on tag pushes: +branches: + except: + - /^v?[0-9]+\.[0-9]+/ -- 2.7.2
Subject: 0003-probe-for-broken-inet_ntop-on-darwin.patch

Message body is not shown because it is too large.

Show quoted text
> the darwin issue is fixed with the 3rd patch.
one more patch is needed. not only with apple, everywhere with socklen_t it is needed. -- Reini Urban
Subject: 0001-inet_ntop-fallback-honor-HAVE_SOCKLEN_T.patch
From 9e4a86211193a26008cfc7f012460f6484f57547 Mon Sep 17 00:00:00 2001 From: Reini Urban <rurban@cpanel.net> Date: Tue, 15 Mar 2016 00:56:59 +0100 Subject: [PATCH] inet_ntop fallback: honor HAVE_SOCKLEN_T This is actually used everywhere, we just didn't use it. --- inet_ntop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git inet_ntop.c inet_ntop.c index 5e28d4f..72eb061 100644 --- inet_ntop.c +++ inet_ntop.c @@ -42,7 +42,7 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, */ const char * inet_ntop(int af, const void *src, char *dst, -# ifdef __APPLE__ +# if defined(HAVE_SOCKLEN_T) socklen_t size # else size_t size -- 2.7.2
linux test results: https://travis-ci.org/rurban/Socket6/builds/116008886 macosx tested manually -- Reini Urban
On 2016-3月-14 月 19:59:38, RURBAN wrote: Show quoted text
> > the darwin issue is fixed with the 3rd patch.
> > one more patch is needed. not only with apple, everywhere with > socklen_t it is needed.
Does the attached patch work for you? Since the diff against configure is large, I excluded it. So, please re-generate configure. And, since the definitions provided by your 1st patch are not related to netdb, I suspect having them by Socket6.
Subject: Socket6-broken-inet_ntop.diff
Index: Socket6.xs =================================================================== --- Socket6.xs (revision 639) +++ Socket6.xs (working copy) @@ -540,7 +540,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.__u6_addr.__u6_addr8[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) @@ -45,5 +45,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) @@ -59,6 +59,13 @@ IPv6_CHECK_FUNC(inet_pton) IPv6_CHECK_FUNC(inet_ntop) +if test $ipv6_cv_inet_ntop = yes; then + IPv6_CHECK_INET_NTOP() + if test $ipv6_cv_can_inet_ntop = no; then + ipv6_cv_inet_ntop=no + fi +fi + if test $ac_cv_lib_inet6_getaddrinfo = yes; then INET6LIBS="-L$ipv6_cv_dir/lib -linet6" fi 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;
On Tue Mar 15 15:59:18 2016, UMEMOTO wrote: Show quoted text
> On 2016-3月-14 月 19:59:38, RURBAN wrote:
> > > the darwin issue is fixed with the 3rd patch.
> > > > one more patch is needed. not only with apple, everywhere with > > socklen_t it is needed.
> > Does the attached patch work for you?
yes, it looks a bit better than mine. works good. but please also add my tests. Show quoted text
> And, since the definitions provided by your 1st patch are not related > to netdb, I suspect having them by Socket6.
Fair. This was a 3rd party request from the RT tracker -- Reini Urban
On Wed Mar 16 08:31:30 2016, RURBAN wrote: Show quoted text
> On Tue Mar 15 15:59:18 2016, UMEMOTO wrote:
> > On 2016-3月-14 月 19:59:38, RURBAN wrote:
> > > > the darwin issue is fixed with the 3rd patch.
> > > > > > one more patch is needed. not only with apple, everywhere with > > > socklen_t it is needed.
> > > > Does the attached patch work for you?
> > yes, it looks a bit better than mine. works good. > but please also add my tests.
Actually, your patch does not enable the fallback code. I've added my tests, and they still fail. The configure probe worked, it said no, and #undef CAN_INET_NTOP is set in config.h just the logic in Socket6.xs is missing
Show quoted text
> Actually, your patch does not enable the fallback code. > I've added my tests, and they still fail. > The configure probe worked, it said no, and #undef CAN_INET_NTOP is > set in config.h > just the logic in Socket6.xs is missing
See the attachment -- Reini Urban
Subject: 0001-add-tests-and-enable-CAN_INET_NTOP.patch
From 7139642c207e082ea4aae368747991cff2d246e6 Mon Sep 17 00:00:00 2001 From: Reini Urban <rurban@cpanel.net> Date: Wed, 16 Mar 2016 14:03:23 +0100 Subject: [PATCH] add tests and enable CAN_INET_NTOP --- Socket6.xs | 4 ++-- t/use.t | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git Socket6.xs Socket6.xs index 682b685..0b14036 100644 --- Socket6.xs +++ Socket6.xs @@ -5,7 +5,7 @@ * Copyright (C) 2000-2008 Hajimu UMEMOTO <ume@mahoroba.org>. * All rights reserved. * - * This moduled is besed on perl5.005_55-v6-19990721 written by KAME + * This moduled is based on perl5.005_55-v6-19990721 written by KAME * Project. * * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. @@ -92,7 +92,7 @@ const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; #define HAVE_GETNAMEINFO 1 #endif -#ifndef HAVE_INET_NTOP +#if !defined(HAVE_INET_NTOP) || !defined(CAN_INET_NTOP) #include "inet_ntop.c" #define HAVE_INET_NTOP 1 #endif diff --git t/use.t t/use.t index 055af26..650eea6 100644 --- t/use.t +++ t/use.t @@ -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,10 @@ my($addr, $port) = getnameinfo($sin, NI_NUMERICHOST | NI_NUMERICSERV); if ($addr eq "127.0.0.1" && $port eq "0") { ok(3); } -exit; -__END__ +ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "::")), "::"); +ok(inet_ntop(AF_INET6, inet_pton(AF_INET6, "::21")), "::21") # this fails under darwin + 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"); -- 2.7.2
Oops, I've re-made a patch. Please give it a try.
Subject: Socket6-broken-inet_ntop-20160317.diff
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");
On Wed Mar 16 12:56:36 2016, UMEMOTO wrote: Show quoted text
> Oops, I've re-made a patch. Please give it a try.
Yes, this is good now. Thanks. Now I'll gonna file this bug at apple :) -- Reini Urban
I updated 0.26 which should fixed the problem. Thank you!!