develooper Front page | perl.perl5.changes | Postings from November 2010

[perl.git] branch blead, updated. v5.13.7-101-g2a25d7b

From:
Chris 'Bingos' Williams
Date:
November 25, 2010 13:13
Subject:
[perl.git] branch blead, updated. v5.13.7-101-g2a25d7b
Message ID:
E1PLj7m-00088a-4D@camel.ams6.corp.booking.com
In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/2a25d7b6d65a21dbe54445c03edf63eb4efa6aff?hp=1be7d6f30dca514e55231f7f2c85ef4f0c2e72ad>

- Log -----------------------------------------------------------------
commit 2a25d7b6d65a21dbe54445c03edf63eb4efa6aff
Author: Paul Evans <leonerd@leonerd.org.uk>
Date:   Thu Nov 25 20:10:25 2010 +0000

    [PATCH 5/5] Added Paul Evans to AUTHORS
    
    Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>

M	AUTHORS

commit a95eb22562ac165cd726fcc44559e3960575806d
Author: Paul Evans <leonerd@leonerd.org.uk>
Date:   Thu Nov 25 20:09:15 2010 +0000

    [PATCH 4/5] Adjust unit tests to cope with new sockaddr_in6 functions in Socket (pulled in via IO::Socket)
    
    Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>

M	ext/B/t/concise-xs.t

commit d3f248d35fa98e3b8b9bcce1b564511eee77b7a3
Author: Paul Evans <leonerd@leonerd.org.uk>
Date:   Thu Nov 25 20:08:05 2010 +0000

    [PATCH 3/3] Provide wrappers for IN6ADDR_ANY and IN6ADDR_LOOPBACK
    
    Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>

M	ext/Socket/Makefile.PL
M	ext/Socket/Socket.pm

commit 4bc6101e53adda82ea90912bd4ea6ca42ed22f3f
Author: Paul Evans <leonerd@leonerd.org.uk>
Date:   Thu Nov 25 20:07:23 2010 +0000

    [PATCH 2/3] Implement sockaddr_in6 wrapper
    
    Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>

M	ext/Socket/Socket.pm

commit c73aa44c20991e800d9dcc1f8c59404c77ce882e
Author: Paul Evans <leonerd@leonerd.org.uk>
Date:   Thu Nov 25 20:06:36 2010 +0000

    [PATCH 1/3] Implement Socket::pack_sockaddr_in6() and unpack_sockaddr_in6()
    
    Signed-off-by: Chris 'BinGOs' Williams <chris@bingosnet.co.uk>

M	ext/Socket/Socket.pm
M	ext/Socket/Socket.xs
M	ext/Socket/t/Socket.t
-----------------------------------------------------------------------

Summary of changes:
 AUTHORS                |    1 +
 ext/B/t/concise-xs.t   |    3 +-
 ext/Socket/Makefile.PL |    8 ++++++
 ext/Socket/Socket.pm   |   48 ++++++++++++++++++++++++++++++++++++++-
 ext/Socket/Socket.xs   |   58 ++++++++++++++++++++++++++++++++++++++++++++++++
 ext/Socket/t/Socket.t  |   24 +++++++++++++++++++-
 6 files changed, 139 insertions(+), 3 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index fdf2be3..2ef434b 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -790,6 +790,7 @@ Paul A Sand			<pas@unh.edu>
 Paul Boven			<p.boven@sara.nl>
 Paul David Fardy		<pdf@morgan.ucs.mun.ca>
 Paul Eggert			<eggert@twinsun.com>
+Paul Evans			<leonerd@leonerd.org.uk>
 Paul Fenwick			<pjf@perltraining.com.au>
 Paul Gaborit			<paul.gaborit@enstimac.fr>
 Paul Green			<Paul.Green@stratus.com>
diff --git a/ext/B/t/concise-xs.t b/ext/B/t/concise-xs.t
index 68abad1..9b42325 100644
--- a/ext/B/t/concise-xs.t
+++ b/ext/B/t/concise-xs.t
@@ -213,12 +213,13 @@ my $testpkgs = {
 			     register_domain recv protocol peername
 			     new listen import getsockopt croak
 			     connected connect configure confess close
-			     carp bind atmark accept
+			     carp bind atmark accept sockaddr_in6
 			     /, $] > 5.009 ? ('blocking') : () ],
 
 		    XS => [qw/ unpack_sockaddr_un unpack_sockaddr_in
 			   sockatmark sockaddr_family pack_sockaddr_un
 			   pack_sockaddr_in inet_ntoa inet_aton
+			   unpack_sockaddr_in6 pack_sockaddr_in6
 			   /],
             # skip inet_ntop and inet_pton as they're not exported by default
 		},
diff --git a/ext/Socket/Makefile.PL b/ext/Socket/Makefile.PL
index 7167aa4..62ecab2 100644
--- a/ext/Socket/Makefile.PL
+++ b/ext/Socket/Makefile.PL
@@ -71,6 +71,14 @@ push @names,
  value => "newSVpvn_flags((char *)&ip_address,sizeof(ip_address), SVs_TEMP)",}
          foreach qw(INADDR_ANY INADDR_LOOPBACK INADDR_NONE INADDR_BROADCAST);
 
+push @names,
+{name => $_, type => "SV",
+ macro=>["#ifdef ${_}_INIT\n",
+         "#endif\n"],
+ pre=>"struct in6_addr ip6_address = ${_}_INIT;",
+ value => "newSVpvn_flags((char *)&ip6_address,sizeof(ip6_address), SVs_TEMP)",}
+	 foreach qw(IN6ADDR_ANY IN6ADDR_LOOPBACK);
+
 WriteConstants(
     PROXYSUBS => {autoload => 1},
     NAME => 'Socket',
diff --git a/ext/Socket/Socket.pm b/ext/Socket/Socket.pm
index da70114..b0a72e5 100644
--- a/ext/Socket/Socket.pm
+++ b/ext/Socket/Socket.pm
@@ -112,6 +112,16 @@ Note - does not return a number.
 Returns the 4-byte 'invalid' ip address.  Normally equivalent
 to inet_aton('255.255.255.255').
 
+=item IN6ADDR_ANY
+
+Returns the 16-byte wildcard IPv6 address. Normally equivalent
+to inet_pton(AF_INET6, "::")
+
+=item IN6ADDR_LOOPBACK
+
+Returns the 16-byte loopback IPv6 address. Normally equivalent
+to inet_pton(AF_INET6, "::1")
+
 =item sockaddr_family SOCKADDR
 
 Takes a sockaddr structure (as returned by pack_sockaddr_in(),
@@ -147,6 +157,29 @@ representing the IP address (you can use inet_ntoa() to convert the
 address to the four-dotted numeric format).  Will croak if the
 structure does not have AF_INET in the right place.
 
+=item sockaddr_in6 PORT, IP6_ADDRESS, [ SCOPE_ID, [ FLOWINFO ] ]
+
+=item sockaddr_in6 SOCKADDR_IN6
+
+In list context, unpacks its SOCKADDR_IN6 argument according to
+unpack_sockaddr_in6(). In scalar context, packs its arguments according to
+pack_sockaddr_in6().
+
+=item pack_sockaddr_in6 PORT, IP6_ADDRESS, [ SCOPE_ID, [ FLOWINFO ] ]
+
+Takes two to four arguments, a port number, an opaque string (as returned by
+inet_pton()), optionally a scope ID number, and optionally a flow label
+number. Returns the sockaddr_in6 structure with those arguments packed in
+with AF_INET6 filled in. IPv6 equivalent of pack_sockaddr_in().
+
+=item unpack_sockaddr_in6 SOCKADDR_IN6
+
+Takes a sockaddr_in6 structure (as returned by pack_sockaddr_in6()) and
+returns an array of four elements: the port number, an opaque string
+representing the IPv6 address, the scope ID, and the flow label. (You can
+use inet_ntop() to convert the address to the usual string format). Will
+croak if the structure does not have AF_INET6 in the right place.
+
 =item sockaddr_un PATHNAME
 
 =item sockaddr_un SOCKADDR_UN
@@ -205,8 +238,10 @@ require XSLoader;
 	sockaddr_family
 	pack_sockaddr_in unpack_sockaddr_in
 	pack_sockaddr_un unpack_sockaddr_un
-	sockaddr_in sockaddr_un
+	pack_sockaddr_in6 unpack_sockaddr_in6
+	sockaddr_in sockaddr_in6 sockaddr_un
 	INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK INADDR_NONE
+	IN6ADDR_ANY IN6ADDR_LOOPBACK
 	AF_802
 	AF_AAL
 	AF_APPLETALK
@@ -421,6 +456,17 @@ sub sockaddr_in {
     }
 }
 
+sub sockaddr_in6 {
+    if (wantarray) {
+	croak "usage:   (port,in6addr,scope_id,flowinfo) = sockaddr_in6(sin6_sv)" unless @_ == 1;
+	unpack_sockaddr_in6(@_);
+    }
+    else {
+	croak "usage:   sin6_sv = sockaddr_in6(port,in6addr,[scope_id,[flowinfo]])" unless @_ >= 2 and @_ <= 4;
+	pack_sockaddr_in6(@_);
+    }
+}
+
 sub sockaddr_un {
     if (wantarray) {
 	croak "usage:   (filename) = sockaddr_un(sun_sv)" unless @_ == 1;
diff --git a/ext/Socket/Socket.xs b/ext/Socket/Socket.xs
index 8d219c4..ce6ec34 100644
--- a/ext/Socket/Socket.xs
+++ b/ext/Socket/Socket.xs
@@ -455,6 +455,64 @@ unpack_sockaddr_in(sin_sv)
 	}
 
 void
+pack_sockaddr_in6(port, sin6_addr, scope_id=0, flowinfo=0)
+	unsigned short	port
+	SV *	sin6_addr
+	unsigned long	scope_id
+	unsigned long	flowinfo
+	CODE:
+	{
+#ifdef AF_INET6
+	struct sockaddr_in6 sin6;
+	char * addrbytes;
+	STRLEN addrlen;
+	if (DO_UTF8(sin6_addr) && !sv_utf8_downgrade(sin6_addr, 1))
+	    croak("Wide character in %s", "Socket::pack_sockaddr_in6");
+	addrbytes = SvPVbyte(sin6_addr, addrlen);
+	if(addrlen != sizeof(sin6.sin6_addr))
+	    croak("Bad arg length %s, length is %d, should be %d",
+		  "Socket::pack_sockaddr_in6", addrlen, sizeof(sin6.sin6_addr));
+	Zero(&sin6, sizeof(sin6), char);
+	sin6.sin6_family = AF_INET6;
+	sin6.sin6_port = htons(port);
+	sin6.sin6_flowinfo = htonl(flowinfo);
+	Copy(addrbytes, &sin6.sin6_addr, sizeof(sin6.sin6_addr), char);
+	sin6.sin6_scope_id = scope_id;
+	ST(0) = newSVpvn_flags((char *)&sin6, sizeof(sin6), SVs_TEMP);
+#else
+	ST(0) = (SV*)not_here("pack_sockaddr_in6");
+#endif
+	}
+
+void
+unpack_sockaddr_in6(sin6_sv)
+	SV *	sin6_sv
+	PPCODE:
+	{
+#ifdef AF_INET6
+	STRLEN addrlen;
+	struct sockaddr_in6 sin6;
+	char * addrbytes = SvPVbyte(sin6_sv, addrlen);
+	if (addrlen != sizeof(sin6))
+	    croak("Bad arg length for %s, length is %d, should be %d",
+		    "Socket::unpack_sockaddr_in6",
+		    addrlen, sizeof(sin6));
+	Copy(addrbytes, &sin6, sizeof(sin6), char);
+	if(sin6.sin6_family != AF_INET6)
+	    croak("Bad address family for %s, got %d, should be %d",
+		    "Socket::unpack_sockaddr_in6",
+		    sin6.sin6_family, AF_INET6);
+	EXTEND(SP, 4);
+	mPUSHi(ntohs(sin6.sin6_port));
+	mPUSHp((char *)&sin6.sin6_addr, sizeof(sin6.sin6_addr));
+	mPUSHi(sin6.sin6_scope_id);
+	mPUSHi(ntohl(sin6.sin6_flowinfo));
+#else
+	ST(0) = (SV*)not_here("pack_sockaddr_in6");
+#endif
+	}
+
+void
 inet_ntop(af, ip_address_sv)
         int     af
         SV *    ip_address_sv
diff --git a/ext/Socket/t/Socket.t b/ext/Socket/t/Socket.t
index 9a6d31f..3cfd840 100644
--- a/ext/Socket/t/Socket.t
+++ b/ext/Socket/t/Socket.t
@@ -12,7 +12,7 @@ BEGIN {
 	
 use Socket qw(:all);
 
-print "1..21\n";
+print "1..26\n";
 
 $has_echo = $^O ne 'MSWin32';
 $alarmed = 0;
@@ -184,3 +184,25 @@ if($Config{d_inetntop} && $Config{d_inetaton}){
     # no IPv6 
     print "ok $_ - skipped on this platform\n" for 19 .. 21;
 }
+
+if(defined eval { AF_INET6() } ) {
+   my $sin6 = pack_sockaddr_in6(0x1234, "0123456789abcdef", 567, 89);
+
+   print "not " unless sockaddr_family($sin6) == AF_INET6;
+   print "ok 22\n";
+
+   print "not " unless (unpack_sockaddr_in6($sin6))[0] == 0x1234;
+   print "ok 23\n";
+
+   print "not " unless (unpack_sockaddr_in6($sin6))[1] == "0123456789abcdef";
+   print "ok 24\n";
+
+   print "not " unless (unpack_sockaddr_in6($sin6))[2] == 567;
+   print "ok 25\n";
+
+   print "not " unless (unpack_sockaddr_in6($sin6))[3] == 89;
+   print "ok 26\n";
+}
+else {
+   print "ok $_ - skipped - no AF_INET6\n" for 22 .. 26;
+}

--
Perl5 Master Repository



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About