=== modified file 'Socket.pm'
--- Socket.pm 2016-08-02 13:52:01 +0000
+++ Socket.pm 2016-08-10 15:39:04 +0000
@@ -184,6 +184,9 @@
this structure is normally what you need for the arguments in bind(),
connect(), and send().
+An undefined $port argument is taken as zero; an undefined $ip_address is
+considered a fatal error.
+
=head2 ($port, $ip_address) = unpack_sockaddr_in $sockaddr
Takes a C<sockaddr_in> structure (as returned by pack_sockaddr_in(),
@@ -213,6 +216,9 @@
number. Returns the C<sockaddr_in6> structure with those arguments packed in
and C<AF_INET6> filled in. IPv6 equivalent of pack_sockaddr_in().
+An undefined $port argument is taken as zero; an undefined $ip6_address is
+considered a fatal error.
+
=head2 ($port, $ip6_address, $scope_id, $flowinfo) = unpack_sockaddr_in6 $sockaddr
Takes a C<sockaddr_in6> structure. Returns a list of four elements: the port
=== modified file 'Socket.xs'
--- Socket.xs 2016-08-01 14:32:19 +0000
+++ Socket.xs 2016-08-10 15:39:04 +0000
@@ -945,11 +945,10 @@
struct sockaddr_in sin;
struct in_addr addr;
STRLEN addrlen;
- unsigned short port;
+ unsigned short port = 0;
char * ip_address;
- if (!SvOK(port_sv))
- croak("Undefined port for %s", "Socket::pack_sockaddr_in");
- port = SvUV(port_sv);
+ if (SvOK(port_sv))
+ port = SvUV(port_sv);
if (!SvOK(ip_address_sv))
croak("Undefined address for %s", "Socket::pack_sockaddr_in");
if (DO_UTF8(ip_address_sv) && !sv_utf8_downgrade(ip_address_sv, 1))
@@ -1017,13 +1016,12 @@
CODE:
{
#ifdef HAS_SOCKADDR_IN6
- unsigned short port;
+ unsigned short port = 0;
struct sockaddr_in6 sin6;
char * addrbytes;
STRLEN addrlen;
- if (!SvOK(port_sv))
- croak("Undefined port for %s", "Socket::pack_sockaddr_in6");
- port = SvUV(port_sv);
+ if (SvOK(port_sv))
+ port = SvUV(port_sv);
if (!SvOK(sin6_addr))
croak("Undefined address for %s", "Socket::pack_sockaddr_in6");
if (DO_UTF8(sin6_addr) && !sv_utf8_downgrade(sin6_addr, 1))
=== modified file 't/sockaddr.t'
--- t/sockaddr.t 2016-08-02 13:48:33 +0000
+++ t/sockaddr.t 2016-08-10 15:39:04 +0000
@@ -83,13 +83,14 @@
my $warnings = 0;
local $SIG{__WARN__} = sub { $warnings++ };
- ok( !eval { pack_sockaddr_in undef, ""; 1 },
- 'pack_sockaddr_in undef port is fatal' );
ok( !eval { pack_sockaddr_in 0, undef; 1 },
'pack_sockaddr_in undef addr is fatal' );
ok( !eval { unpack_sockaddr_in undef; 1 },
'unpack_sockaddr_in undef is fatal' );
+ ok( eval { pack_sockaddr_in undef, "\0\0\0\0"; 1 },
+ 'pack_sockaddr_in undef port is allowed' );
+
is( $warnings, 0, 'undefined values produced no warnings' );
}
@@ -118,13 +119,14 @@
my $warnings = 0;
local $SIG{__WARN__} = sub { $warnings++ };
- ok( !eval { Socket::pack_sockaddr_in6( undef, "" ); 1 },
- 'pack_sockaddr_in6 undef port is fatal' );
ok( !eval { Socket::pack_sockaddr_in6( 0, undef ); 1 },
'pack_sockaddr_in6 undef addr is fatal' );
ok( !eval { Socket::unpack_sockaddr_in6( undef ); 1 },
'unpack_sockaddr_in6 undef is fatal' );
+ ok( eval { Socket::pack_sockaddr_in6( undef, "\0"x16 ); 1 },
+ 'pack_sockaddr_in6 undef port is allowed' );
+
is( $warnings, 0, 'undefined values produced no warnings' );
}