diff options
author | Florian Ragwitz <rafl@debian.org> | 2011-12-01 15:23:25 +0100 |
---|---|---|
committer | Florian Ragwitz <rafl@debian.org> | 2011-12-01 15:23:25 +0100 |
commit | 8cbe2351fa9be7ae959bf6c99a37820fe1c534c4 (patch) | |
tree | 910b2f22366eab260a1ea51d1e690dcee56e3ecd | |
parent | 0beff067932254cd3dc853ac18c0e666b9e4cd75 (diff) | |
parent | f72af2d244e61d9be2e55bb64a2eeb11fa8968e3 (diff) | |
download | perl-8cbe2351fa9be7ae959bf6c99a37820fe1c534c4.tar.gz |
Merge branch 'dual-life-socket' into blead
* dual-life-socket:
Bump Socket::VERSION to 1.95; to match CPAN release
Snapshot of P/PE/PEVANS/Socket-1.94_07.tar.gz
More fixups for dual-life to support out-of-core build
Prepare Socket.pm for dual-life
Fixups for older Perl versions:
Rewrite ext/Socket/t/Socket.t to use Test::More rather than manual printing
-rw-r--r-- | MANIFEST | 16 | ||||
-rwxr-xr-x | Porting/Maintainers.pl | 8 | ||||
-rw-r--r-- | cpan/Socket/.gitignore (renamed from ext/Socket/.gitignore) | 0 | ||||
-rw-r--r-- | cpan/Socket/Makefile.PL (renamed from ext/Socket/Makefile.PL) | 93 | ||||
-rw-r--r-- | cpan/Socket/Socket.pm (renamed from ext/Socket/Socket.pm) | 65 | ||||
-rw-r--r-- | cpan/Socket/Socket.xs (renamed from ext/Socket/Socket.xs) | 12 | ||||
-rw-r--r-- | cpan/Socket/t/Socket.t | 184 | ||||
-rw-r--r-- | cpan/Socket/t/getaddrinfo.t (renamed from ext/Socket/t/getaddrinfo.t) | 0 | ||||
-rw-r--r-- | cpan/Socket/t/getnameinfo.t (renamed from ext/Socket/t/getnameinfo.t) | 0 | ||||
-rw-r--r-- | cpan/Socket/t/ipv6_mreq.t (renamed from ext/Socket/t/ipv6_mreq.t) | 0 | ||||
-rw-r--r-- | cpan/Socket/t/socketpair.t (renamed from ext/Socket/t/socketpair.t) | 0 | ||||
-rw-r--r-- | ext/Socket/t/Socket.t | 213 |
12 files changed, 350 insertions, 241 deletions
@@ -2169,6 +2169,14 @@ cpan/Pod-Simple/t/xhtml05.t Pod::Simple test file cpan/Pod-Simple/t/xhtml10.t Pod::Simple test file cpan/Pod-Simple/t/xhtml15.t Pod::Simple test file cpan/Pod-Simple/t/x_nixer.t Pod::Simple test file +cpan/Socket/Makefile.PL Socket extension makefile writer +cpan/Socket/Socket.pm Socket extension Perl module +cpan/Socket/Socket.xs Socket extension external subroutines +cpan/Socket/t/getaddrinfo.t See if Socket::getaddrinfo works +cpan/Socket/t/getnameinfo.t See if Socket::getnameinfo works +cpan/Socket/t/ipv6_mreq.t See if (un)pack_ipv6_mreq work +cpan/Socket/t/socketpair.t See if socketpair works +cpan/Socket/t/Socket.t See if Socket works cpan/Sys-Syslog/Changes Changelog for Sys::Syslog cpan/Sys-Syslog/fallback/const-c.inc Sys::Syslog constants fallback file cpan/Sys-Syslog/fallback/const-xs.inc Sys::Syslog constants fallback file @@ -3859,14 +3867,6 @@ ext/SDBM_File/sdbm/tune.h SDBM kit ext/SDBM_File/sdbm/util.c SDBM kit ext/SDBM_File/t/sdbm.t See if SDBM_File works ext/SDBM_File/typemap SDBM extension interface types -ext/Socket/Makefile.PL Socket extension makefile writer -ext/Socket/Socket.pm Socket extension Perl module -ext/Socket/Socket.xs Socket extension external subroutines -ext/Socket/t/getaddrinfo.t See if Socket::getaddrinfo works -ext/Socket/t/getnameinfo.t See if Socket::getnameinfo works -ext/Socket/t/ipv6_mreq.t See if (un)pack_ipv6_mreq work -ext/Socket/t/socketpair.t See if socketpair works -ext/Socket/t/Socket.t See if Socket works ext/Sys-Hostname/Hostname.pm Sys::Hostname extension Perl module ext/Sys-Hostname/Hostname.xs Sys::Hostname extension external subroutines ext/Sys-Hostname/t/Hostname.t See if Sys::Hostname works diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl index 97037c79fd..aa5dfc066a 100755 --- a/Porting/Maintainers.pl +++ b/Porting/Maintainers.pl @@ -65,6 +65,7 @@ use File::Glob qw(:case); 'p5p' => 'perl5-porters <perl5-porters@perl.org>', 'perlfaq' => 'perlfaq-workers <perlfaq-workers@perl.org>', 'petdance' => 'Andy Lester <andy@petdance.com>', + 'pevans' => 'Paul Evans <leonerd@leonerd.org.uk>', 'pjf' => 'Paul Fenwick <pjf@cpan.org>', 'pmqs' => 'Paul Marquess <pmqs@cpan.org>', 'pvhp' => 'Peter Prymmer <pvhp@best.com>', @@ -1663,9 +1664,10 @@ use File::Glob qw(:case); 'Socket' => { - 'MAINTAINER' => 'p5p', - 'FILES' => q[ext/Socket], - 'UPSTREAM' => 'blead', + 'MAINTAINER' => 'pevans', + 'DISTRIBUTION' => 'PEVANS/Socket-1.95.tar.gz', + 'FILES' => q[cpan/Socket], + 'UPSTREAM' => 'cpan', }, 'Storable' => diff --git a/ext/Socket/.gitignore b/cpan/Socket/.gitignore index 2a06e93b55..2a06e93b55 100644 --- a/ext/Socket/.gitignore +++ b/cpan/Socket/.gitignore diff --git a/ext/Socket/Makefile.PL b/cpan/Socket/Makefile.PL index 83908116f3..5518e33f88 100644 --- a/ext/Socket/Makefile.PL +++ b/cpan/Socket/Makefile.PL @@ -1,12 +1,90 @@ use ExtUtils::MakeMaker; use ExtUtils::Constant 0.23 'WriteConstants'; use Config; + +my @DEFINES; +unless( $ENV{PERL_CORE} ) { + # Building standalone, not as core. + require ExtUtils::CChecker; + my $cc = ExtUtils::CChecker->new; + + my %defines = ( + # -Dfoo func() $Config{key} + HAS_GETADDRINFO => [ "getaddrinfo", "d_getaddrinfo" ], + HAS_GETNAMEINFO => [ "getnameinfo", "d_getnameinfo" ], + HAS_INET_ATON => [ "inet_aton", "d_inetaton" ], + HAS_INETNTOP => [ "inet_ntop", "d_inetntop" ], + HAS_INETPTON => [ "inet_pton", "d_inetpton" ], + ); + + foreach my $define ( sort keys %defines ) { + my ( $func, $key ) = @{$defines{$define}}; + next if exists $Config{$key}; + + $cc->try_compile_run( + define => $define, + source => <<"EOF" ) +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <netinet/in.h> +#include <arpa/inet.h> +int main(int argc, char *argv[]) { + void *p = &$func; + return 0; +} +EOF + and print "$func() found\n" + or print "$func() not found\n"; + } + + unless( exists $Config{d_sockaddr_sa_len} ) { + $cc->try_compile_run( + define => "HAS_SOCKADDR_SA_LEN", + source => <<'EOF' ) +#include <sys/types.h> +#include <sys/socket.h> +int main(int argc, char *argv[]) { + struct sockaddr sa; + sa.sa_len = 0; + return 0; +} +EOF + and print "sockaddr has sa_len\n" + or print "sockaddr does not have sa_len\n"; + } + + unless( exists $Config{d_sin6_scope_id} ) { + $cc->try_compile_run( + define => "HAS_SIN6_SCOPE_ID", + source => <<'EOF' ) +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +int main(int argc, char *argv[]) { + struct sockaddr_in6 sin6; + sin6.sin6_scope_id = 0; + return 0; +} +EOF + and print "sockaddr_in6 has sin6_scope_id\n" + or print "sockaddr_in6 does not have sin6_scope_id\n"; + } + + @DEFINES = @{ $cc->extra_compiler_flags }; +} + WriteMakefile( NAME => 'Socket', VERSION_FROM => 'Socket.pm', ($Config{libs} =~ /(-lsocks\S*)/ ? (LIBS => [ "$1" ] ) : ()), XSPROTOARG => '-noprototypes', # XXX remove later? realclean => {FILES=> 'const-c.inc const-xs.inc'}, + DEFINE => join( " ", @DEFINES ), + CONFIGURE_REQUIRES => { + 'ExtUtils::CChecker' => 0, + 'ExtUtils::Constant' => '0.23', + }, ); my @names = (qw(AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF AF_DATAKIT AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK @@ -14,9 +92,12 @@ my @names = (qw(AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF AF_LAST AF_LAT AF_LINK AF_MAX AF_NBS AF_NIT AF_NS AF_OSI AF_OSINET AF_PUP AF_ROUTE AF_SNA AF_UNIX AF_UNSPEC AF_USER AF_WAN AF_X25 - AI_CANONNAME AI_NUMERICHOST AI_NUMERICSERV AI_PASSIVE - EAI_ADDRFAMILY EAI_AGAIN EAI_BADFLAGS EAI_FAIL EAI_FAMILY - EAI_NODATA EAI_NONAME EAI_SERVICE EAI_SOCKTYPE + AI_ADDRCONFIG AI_ALL AI_CANONIDN AI_CANONNAME AI_IDN + AI_IDN_ALLOW_UNASSIGNED AI_IDN_USE_STD3_ASCII_RULES + AI_NUMERICHOST AI_NUMERICSERV AI_PASSIVE AI_V4MAPPED + EAI_ADDRFAMILY EAI_AGAIN EAI_BADFLAGS EAI_BADHINTS EAI_FAIL + EAI_FAMILY EAI_NODATA EAI_NONAME EAI_PROTOCOL EAI_SERVICE + EAI_SOCKTYPE EAI_SYSTEM IOV_MAX IP_OPTIONS IP_HDRINCL IP_TOS IP_TTL IP_RECVOPTS IP_RECVRETOPTS IP_RETOPTS IPV6_ADD_MEMBERSHIP IPV6_DROP_MEMBERSHIP IPV6_MTU @@ -26,7 +107,9 @@ my @names = (qw(AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF MSG_EOF MSG_EOR MSG_ERRQUEUE MSG_ETAG MSG_FIN MSG_MAXIOVLEN MSG_MCAST MSG_NOSIGNAL MSG_RST MSG_SYN MSG_TRUNC MSG_URG MSG_WAITALL MSG_WIRE - NI_DGRAM NI_NAMEREQD NI_NUMERICHOST NI_NUMERICSERV + NI_DGRAM NI_IDN NI_IDN_ALLOW_UNASSIGNED + NI_IDN_USE_STD3_ASCII_RULES NI_NAMEREQD NI_NOFQDN + NI_NUMERICHOST NI_NUMERICSERV PF_802 PF_AAL PF_APPLETALK PF_CCITT PF_CHAOS PF_CTF PF_DATAKIT PF_DECnet PF_DLI PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_INET6 PF_ISO PF_KEY @@ -72,7 +155,7 @@ push @names, "#endif\n"]} foreach qw (MSG_CTRUNC MSG_DONTROUTE MSG_OOB MSG_PEEK MSG_PROXY SCM_RIGHTS); -push @names, +push @names, {name => $_, type => "SV", pre=>"struct in_addr ip_address; ip_address.s_addr = htonl($_);", value => "newSVpvn_flags((char *)&ip_address,sizeof(ip_address), SVs_TEMP)",} diff --git a/ext/Socket/Socket.pm b/cpan/Socket/Socket.pm index d82aa2bfaf..2cf8687c76 100644 --- a/ext/Socket/Socket.pm +++ b/cpan/Socket/Socket.pm @@ -3,11 +3,11 @@ package Socket; use strict; our($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); -$VERSION = "1.94_03"; +$VERSION = "1.95"; =head1 NAME -Socket, sockaddr_in, sockaddr_un, inet_aton, inet_ntoa, inet_pton, inet_ntop - load the C socket.h defines and structure manipulators +Socket, sockaddr_in, sockaddr_un, inet_aton, inet_ntoa, inet_pton, inet_ntop - load the C socket.h defines and structure manipulators =head1 SYNOPSIS @@ -43,7 +43,7 @@ Socket, sockaddr_in, sockaddr_un, inet_aton, inet_ntoa, inet_pton, inet_ntop - l This module is just a translation of the C F<socket.h> file. Unlike the old mechanism of requiring a translated F<socket.ph> file, this uses the B<h2xs> program (see the Perl source distribution) -and your native C compiler. This means that it has a +and your native C compiler. This means that it has a far more likely chance of getting the numbers right. This includes all of the commonly used pound-defines like AF_INET, SOCK_STREAM, etc. @@ -210,7 +210,7 @@ have AF_UNIX in the right place. Takes an address family, either AF_INET or AF_INET6, and a string giving the name of a host, and translates that to an opaque string -(if programming in C, struct in_addr or struct in6_addr depending on the +(if programming in C, struct in_addr or struct in6_addr depending on the address family passed in). The host string may be a string hostname, such as 'www.perl.org', or an IP address. If using an IP address, the type of IP address must be consistent with the address family passed into the function. @@ -219,7 +219,7 @@ This function is not exported by default. =item inet_ntop ADDRESS_FAMILY, IP_ADDRESS -Takes an address family, either AF_INET or AF_INET6, and a string +Takes an address family, either AF_INET or AF_INET6, and a string (an opaque string as returned by inet_aton() or inet_pton()) and translates it to an IPv4 or IPv6 address string. @@ -506,20 +506,30 @@ require XSLoader; IN6ADDR_ANY IN6ADDR_LOOPBACK + AI_ADDRCONFIG + AI_ALL + AI_CANONIDN AI_CANONNAME + AI_IDN + AI_IDN_ALLOW_UNASSIGNED + AI_IDN_USE_STD3_ASCII_RULES AI_NUMERICHOST AI_NUMERICSERV AI_PASSIVE + AI_V4MAPPED EAI_ADDRFAMILY EAI_AGAIN EAI_BADFLAGS + EAI_BADHINTS EAI_FAIL EAI_FAMILY EAI_NODATA EAI_NONAME + EAI_PROTOCOL EAI_SERVICE EAI_SOCKTYPE + EAI_SYSTEM IPPROTO_IP IPPROTO_IPV6 @@ -539,7 +549,11 @@ require XSLoader; IPV6_V6ONLY NI_DGRAM + NI_IDN + NI_IDN_ALLOW_UNASSIGNED + NI_IDN_USE_STD3_ASCII_RULES NI_NAMEREQD + NI_NOFQDN NI_NUMERICHOST NI_NUMERICSERV @@ -579,7 +593,7 @@ BEGIN { sub sockaddr_in { if (@_ == 6 && !wantarray) { # perl5.001m compat; use this && die my($af, $port, @quad) = @_; - warnings::warn "6-ARG sockaddr_in call is deprecated" + warnings::warn "6-ARG sockaddr_in call is deprecated" if warnings::enabled(); pack_sockaddr_in($port, inet_aton(join('.', @quad))); } elsif (wantarray) { @@ -612,7 +626,7 @@ sub sockaddr_un { } } -XSLoader::load(); +XSLoader::load(__PACKAGE__, $VERSION); my %errstr; @@ -634,6 +648,9 @@ if( defined &getaddrinfo ) { AI_PASSIVE => 1, AI_CANONNAME => 2, AI_NUMERICHOST => 4, + AI_V4MAPPED => 8, + AI_ALL => 16, + AI_ADDRCONFIG => 32, # RFC 2553 doesn't define this but Linux does - lets be nice and # provide it since we can AI_NUMERICSERV => 1024, @@ -646,8 +663,25 @@ if( defined &getaddrinfo ) { NI_NUMERICHOST => 1, NI_NUMERICSERV => 2, + NI_NOFQDN => 4, NI_NAMEREQD => 8, NI_DGRAM => 16, + + # Constants we don't support. Export them, but croak if anyone tries to + # use them + AI_IDN => 64, + AI_CANONIDN => 128, + AI_IDN_ALLOW_UNASSIGNED => 256, + AI_IDN_USE_STD3_ASCII_RULES => 512, + NI_IDN => 32, + NI_IDN_ALLOW_UNASSIGNED => 64, + NI_IDN_USE_STD3_ASCII_RULES => 128, + + # Error constants we'll never return, so it doesn't matter what value + # these have, nor that we don't provide strings for them + EAI_SYSTEM => -11, + EAI_BADHINTS => -1000, + EAI_PROTOCOL => -1001 ); foreach my $name ( keys %constants ) { @@ -706,6 +740,14 @@ sub fake_getaddrinfo my $flag_numerichost = $flags & AI_NUMERICHOST(); $flags &= ~AI_NUMERICHOST(); my $flag_numericserv = $flags & AI_NUMERICSERV(); $flags &= ~AI_NUMERICSERV(); + # These constants don't apply to AF_INET-only lookups, so we might as well + # just ignore them. For AI_ADDRCONFIG we just presume the host has ability + # to talk AF_INET. If not we'd have to return no addresses at all. :) + $flags &= ~(AI_V4MAPPED()|AI_ALL()|AI_ADDRCONFIG()); + + $flags & (AI_IDN()|AI_CANONIDN()|AI_IDN_ALLOW_UNASSIGNED()|AI_IDN_USE_STD3_ASCII_RULES()) and + croak "Socket::getaddrinfo() does not support IDN"; + $flags == 0 or return fake_makeerr( EAI_BADFLAGS() ); $node eq "" and $service eq "" and return fake_makeerr( EAI_NONAME() ); @@ -797,9 +839,13 @@ sub fake_getnameinfo my $flag_numerichost = $flags & NI_NUMERICHOST(); $flags &= ~NI_NUMERICHOST(); my $flag_numericserv = $flags & NI_NUMERICSERV(); $flags &= ~NI_NUMERICSERV(); + my $flag_nofqdn = $flags & NI_NOFQDN(); $flags &= ~NI_NOFQDN(); my $flag_namereqd = $flags & NI_NAMEREQD(); $flags &= ~NI_NAMEREQD(); my $flag_dgram = $flags & NI_DGRAM() ; $flags &= ~NI_DGRAM(); + $flags & (NI_IDN()|NI_IDN_ALLOW_UNASSIGNED()|NI_IDN_USE_STD3_ASCII_RULES()) and + croak "Socket::getnameinfo() does not support IDN"; + $flags == 0 or return fake_makeerr( EAI_BADFLAGS() ); my $node; @@ -812,6 +858,11 @@ sub fake_getnameinfo return fake_makeerr( EAI_NONAME() ) if $flag_namereqd; $node = Socket::inet_ntoa( $inetaddr ); } + elsif( $flag_nofqdn ) { + my ( $shortname ) = split m/\./, $node; + my ( $fqdn ) = gethostbyname $shortname; + $node = $shortname if defined $fqdn and $fqdn eq $node; + } } my $service; diff --git a/ext/Socket/Socket.xs b/cpan/Socket/Socket.xs index e164e67259..b06cfa6bea 100644 --- a/ext/Socket/Socket.xs +++ b/cpan/Socket/Socket.xs @@ -71,6 +71,10 @@ NETINET_DEFINE_CONTEXT # define INADDR_LOOPBACK 0x7F000001 #endif /* INADDR_LOOPBACK */ +#ifndef croak_sv +# define croak_sv(sv) croak(SvPV_nolen(sv)) +#endif + #ifndef HAS_INET_ATON /* @@ -237,7 +241,6 @@ static SV *err_to_SV(pTHX_ int err) static void xs_getaddrinfo(pTHX_ CV *cv) { - dVAR; dXSARGS; SV *host; @@ -254,7 +257,7 @@ static void xs_getaddrinfo(pTHX_ CV *cv) int n_res; if(items > 3) - croak_xs_usage(cv, "host, service, hints"); + croak("Usage: Socket::getaddrinfo(host, service, hints)"); SP -= items; @@ -344,7 +347,6 @@ static void xs_getaddrinfo(pTHX_ CV *cv) #ifdef HAS_GETNAMEINFO static void xs_getnameinfo(pTHX_ CV *cv) { - dVAR; dXSARGS; SV *addr; @@ -357,7 +359,7 @@ static void xs_getnameinfo(pTHX_ CV *cv) int err; if(items < 1 || items > 2) - croak_xs_usage(cv, "addr, flags=0"); + croak("Usage: Socket::getnameinfo(addr, flags=0)"); SP -= items; @@ -540,7 +542,7 @@ pack_sockaddr_un(pathname) #else ST(0) = (SV *) not_here("pack_sockaddr_un"); #endif - + } void diff --git a/cpan/Socket/t/Socket.t b/cpan/Socket/t/Socket.t new file mode 100644 index 0000000000..f59c265c4c --- /dev/null +++ b/cpan/Socket/t/Socket.t @@ -0,0 +1,184 @@ +#!./perl + +BEGIN { + require Config; import Config; + if ($Config{'extensions'} !~ /\bSocket\b/ && + !(($^O eq 'VMS') && $Config{d_socket})) { + print "1..0\n"; + exit 0; + } + $has_alarm = $Config{d_alarm}; +} + +use Socket qw(:all); +use Test::More tests => 26; + +$has_echo = $^O ne 'MSWin32'; +$alarmed = 0; +sub arm { $alarmed = 0; alarm(shift) if $has_alarm } +sub alarmed { $alarmed = 1 } +$SIG{ALRM} = 'alarmed' if $has_alarm; + +SKIP: { + unless(socket(T, PF_INET, SOCK_STREAM, IPPROTO_TCP)) { + skip "No PF_INET", 3; + } + + pass "socket(PF_INET)"; + + arm(5); + my $host = $^O eq 'MacOS' || ($^O eq 'irix' && $Config{osvers} == 5) ? + '127.0.0.1' : 'localhost'; + my $localhost = inet_aton($host); + + SKIP: { + unless($has_echo && defined $localhost && connect(T,pack_sockaddr_in(7,$localhost))) { + skip "Unable to connect to localhost:7", 2; + } + + arm(0); + + pass "PF_INET echo localhost connected"; + + diag "Connected to " . + inet_ntoa((unpack_sockaddr_in(getpeername(T)))[1])."\n"; + + arm(5); + syswrite(T,"hello",5); + arm(0); + + arm(5); + $read = sysread(T,$buff,10); # Connection may be granted, then closed! + arm(0); + + while ($read > 0 && length($buff) < 5) { + # adjust for fact that TCP doesn't guarantee size of reads/writes + arm(5); + $read = sysread(T,$buff,10,length($buff)); + arm(0); + } + + is(($read == 0 || $buff eq "hello"), "PF_INET echo localhost reply"); + } +} + +SKIP: { + unless(socket(S, PF_INET, SOCK_STREAM, IPPROTO_TCP)) { + skip "No PF_INET", 3; + } + + pass "socket(PF_INET)"; + + SKIP: { + arm(5); + unless($has_echo && connect(S,pack_sockaddr_in(7,INADDR_LOOPBACK))) { + skip "Unable to connect to localhost:7", 2; + } + + arm(0); + + pass "PF_INET echo INADDR_LOOPBACK connected"; + + diag "Connected to " . + inet_ntoa((unpack_sockaddr_in(getpeername(S)))[1])."\n"; + + arm(5); + syswrite(S,"olleh",5); + arm(0); + + arm(5); + $read = sysread(S,$buff,10); # Connection may be granted, then closed! + arm(0); + + while ($read > 0 && length($buff) < 5) { + # adjust for fact that TCP doesn't guarantee size of reads/writes + arm(5); + $read = sysread(S,$buff,10,length($buff)); + arm(0); + } + + is(($read == 0 || $buff eq "olleh"), "PF_INET echo INADDR_LOOPBACK reply"); + } +} + +# warnings +{ + my $w = 0; + local $SIG{__WARN__} = sub { + ++ $w if $_[0] =~ /^6-ARG sockaddr_in call is deprecated/ ; + }; + + no warnings 'Socket'; + sockaddr_in(1,2,3,4,5,6) ; + is($w, 0, "sockaddr_in deprecated form doesn't warn without lexical warnings"); + + use warnings 'Socket'; + sockaddr_in(1,2,3,4,5,6) ; + is($w, 1, "sockaddr_in deprecated form warns with lexical warnings"); +} + +# Test that whatever we give into pack/unpack_sockaddr retains +# the value thru the entire chain. +is(inet_ntoa((unpack_sockaddr_in(pack_sockaddr_in(100,inet_aton("10.250.230.10"))))[1]), '10.250.230.10', + 'inet_aton->pack_sockaddr_in->unpack_sockaddr_in->inet_ntoa roundtrip'); + +is(inet_ntoa(inet_aton("10.20.30.40")), "10.20.30.40", 'inet_aton->inet_ntoa roundtrip'); +is(inet_ntoa(v10.20.30.40), "10.20.30.40", 'inet_ntoa from v-string'); + +{ + my ($port,$addr) = unpack_sockaddr_in(pack_sockaddr_in(100,v10.10.10.10)); + is($port, 100, 'pack_sockaddr_in->unpack_sockaddr_in port'); + is(inet_ntoa($addr), "10.10.10.10", 'pack_sockaddr_in->unpack_sockaddr_in addr'); +} + +{ + local $@; + eval { inet_ntoa(v10.20.30.400) }; + like($@, qr/^Wide character in Socket::inet_ntoa at/, 'inet_ntoa warns about wide characters'); +} + +is(sockaddr_family(pack_sockaddr_in(100,inet_aton("10.250.230.10"))), AF_INET, 'pack_sockaddr_in->sockaddr_family'); + +{ + local $@; + eval { sockaddr_family("") }; + like($@, qr/^Bad arg length for Socket::sockaddr_family, length is 0, should be at least \d+/, 'sockaddr_family warns about argument length'); +} + +SKIP: { + # see if we can handle abstract sockets + skip "Abstract AF_UNIX paths unsupported", 2 unless $^O eq "linux"; + + my $test_abstract_socket = chr(0) . '/org/perl/hello'. chr(0) . 'world'; + my $addr = sockaddr_un ($test_abstract_socket); + my ($path) = sockaddr_un ($addr); + is($path, $test_abstract_socket, 'sockaddr_un can handle abstract AF_UNIX paths'); + + # see if we calculate the address structure length correctly + is(length ($test_abstract_socket) + 2, length $addr, 'sockaddr_un abstract address length'); +} + +SKIP: { + skip "No inet_ntop", 3 unless $Config{d_inetntop} && $Config{d_inetaton}; + + is(inet_ntop(AF_INET, inet_pton(AF_INET, "10.20.30.40")), "10.20.30.40", 'inet_pton->inet_ntop AF_INET roundtrip'); + is(inet_ntop(AF_INET, inet_aton("10.20.30.40")), "10.20.30.40", 'inet_aton->inet_ntop AF_INET roundtrip'); + + SKIP: { + skip "No AF_INET6", 1 unless defined eval { AF_INET6() }; + is(lc inet_ntop(AF_INET6, inet_pton(AF_INET6, "2001:503:BA3E::2:30")), "2001:503:ba3e::2:30", 'inet_pton->inet_ntop AF_INET6 roundtrip'); + } +} + +SKIP: { + skip "No AF_INET6", 5 unless defined eval { AF_INET6() }; + + my $sin6 = pack_sockaddr_in6(0x1234, "0123456789abcdef", 0, 89); + + is(sockaddr_family($sin6), AF_INET6, 'sockaddr_family of pack_sockaddr_in6'); + + is((unpack_sockaddr_in6($sin6))[0], 0x1234, 'pack_sockaddr_in6->unpack_sockaddr_in6 port'); + is((unpack_sockaddr_in6($sin6))[1], "0123456789abcdef", 'pack_sockaddr_in6->unpack_sockaddr_in6 addr'); + is((unpack_sockaddr_in6($sin6))[2], 0, 'pack_sockaddr_in6->unpack_sockaddr_in6 scope_id'); + is((unpack_sockaddr_in6($sin6))[3], 89, 'pack_sockaddr_in6->unpack_sockaddr_in6 flowinfo'); +} diff --git a/ext/Socket/t/getaddrinfo.t b/cpan/Socket/t/getaddrinfo.t index b85af38254..b85af38254 100644 --- a/ext/Socket/t/getaddrinfo.t +++ b/cpan/Socket/t/getaddrinfo.t diff --git a/ext/Socket/t/getnameinfo.t b/cpan/Socket/t/getnameinfo.t index 803e8c0c57..803e8c0c57 100644 --- a/ext/Socket/t/getnameinfo.t +++ b/cpan/Socket/t/getnameinfo.t diff --git a/ext/Socket/t/ipv6_mreq.t b/cpan/Socket/t/ipv6_mreq.t index 43fb8f804b..43fb8f804b 100644 --- a/ext/Socket/t/ipv6_mreq.t +++ b/cpan/Socket/t/ipv6_mreq.t diff --git a/ext/Socket/t/socketpair.t b/cpan/Socket/t/socketpair.t index 997628c3bd..997628c3bd 100644 --- a/ext/Socket/t/socketpair.t +++ b/cpan/Socket/t/socketpair.t diff --git a/ext/Socket/t/Socket.t b/ext/Socket/t/Socket.t deleted file mode 100644 index 326fa7a9ef..0000000000 --- a/ext/Socket/t/Socket.t +++ /dev/null @@ -1,213 +0,0 @@ -#!./perl - -BEGIN { - require Config; import Config; - if ($Config{'extensions'} !~ /\bSocket\b/ && - !(($^O eq 'VMS') && $Config{d_socket})) { - print "1..0\n"; - exit 0; - } - $has_alarm = $Config{d_alarm}; -} - -use Socket qw(:all); - -print "1..26\n"; - -$has_echo = $^O ne 'MSWin32'; -$alarmed = 0; -sub arm { $alarmed = 0; alarm(shift) if $has_alarm } -sub alarmed { $alarmed = 1 } -$SIG{ALRM} = 'alarmed' if $has_alarm; - -if (socket(T, PF_INET, SOCK_STREAM, IPPROTO_TCP)) { - print "ok 1\n"; - - arm(5); - my $host = $^O eq 'MacOS' || ($^O eq 'irix' && $Config{osvers} == 5) ? - '127.0.0.1' : 'localhost'; - my $localhost = inet_aton($host); - - if ($has_echo && defined $localhost && connect(T,pack_sockaddr_in(7,$localhost))){ - arm(0); - - print "ok 2\n"; - - print "# Connected to " . - inet_ntoa((unpack_sockaddr_in(getpeername(T)))[1])."\n"; - - arm(5); - syswrite(T,"hello",5); - arm(0); - - arm(5); - $read = sysread(T,$buff,10); # Connection may be granted, then closed! - arm(0); - - while ($read > 0 && length($buff) < 5) { - # adjust for fact that TCP doesn't guarantee size of reads/writes - arm(5); - $read = sysread(T,$buff,10,length($buff)); - arm(0); - } - print(($read == 0 || $buff eq "hello") ? "ok 3\n" : "not ok 3\n"); - } - else { - print "# You're allowed to fail tests 2 and 3 if\n"; - print "# the echo service has been disabled or if your\n"; - print "# gethostbyname() cannot resolve your localhost.\n"; - print "# 'Connection refused' indicates disabled echo service.\n"; - print "# 'Interrupted system call' indicates a hanging echo service.\n"; - print "# Error: $!\n"; - print "ok 2 - skipped\n"; - print "ok 3 - skipped\n"; - } -} -else { - print "# Error: $!\n"; - print "not ok 1\n"; -} - -if( socket(S, PF_INET,SOCK_STREAM, IPPROTO_TCP) ){ - print "ok 4\n"; - - arm(5); - if ($has_echo && connect(S,pack_sockaddr_in(7,INADDR_LOOPBACK))){ - arm(0); - - print "ok 5\n"; - - print "# Connected to " . - inet_ntoa((unpack_sockaddr_in(getpeername(S)))[1])."\n"; - - arm(5); - syswrite(S,"olleh",5); - arm(0); - - arm(5); - $read = sysread(S,$buff,10); # Connection may be granted, then closed! - arm(0); - - while ($read > 0 && length($buff) < 5) { - # adjust for fact that TCP doesn't guarantee size of reads/writes - arm(5); - $read = sysread(S,$buff,10,length($buff)); - arm(0); - } - print(($read == 0 || $buff eq "olleh") ? "ok 6\n" : "not ok 6\n"); - } - else { - print "# You're allowed to fail tests 5 and 6 if\n"; - print "# the echo service has been disabled.\n"; - print "# 'Interrupted system call' indicates a hanging echo service.\n"; - print "# Error: $!\n"; - print "ok 5 - skipped\n"; - print "ok 6 - skipped\n"; - } -} -else { - print "# Error: $!\n"; - print "not ok 4\n"; -} - -# warnings -$SIG{__WARN__} = sub { - ++ $w if $_[0] =~ /^6-ARG sockaddr_in call is deprecated/ ; -} ; -$w = 0 ; -sockaddr_in(1,2,3,4,5,6) ; -print ($w == 1 ? "not ok 7\n" : "ok 7\n") ; -use warnings 'Socket' ; -sockaddr_in(1,2,3,4,5,6) ; -print ($w == 1 ? "ok 8\n" : "not ok 8\n") ; - -# Thest that whatever we give into pack/unpack_sockaddr retains -# the value thru the entire chain. -if((inet_ntoa((unpack_sockaddr_in(pack_sockaddr_in(100,inet_aton("10.250.230.10"))))[1])) eq '10.250.230.10') { - print "ok 9\n"; -} else { - print "not ok 9\n"; -} -print ((inet_ntoa(inet_aton("10.20.30.40")) eq "10.20.30.40") ? "ok 10\n" : "not ok 10\n"); -print ((inet_ntoa(v10.20.30.40) eq "10.20.30.40") ? "ok 11\n" : "not ok 11\n"); -{ - my ($port,$addr) = unpack_sockaddr_in(pack_sockaddr_in(100,v10.10.10.10)); - print (($port == 100) ? "ok 12\n" : "not ok 12\n"); - print ((inet_ntoa($addr) eq "10.10.10.10") ? "ok 13\n" : "not ok 13\n"); -} - -eval { inet_ntoa(v10.20.30.400) }; -print (($@ =~ /^Wide character in Socket::inet_ntoa at/) ? "ok 14\n" : "not ok 14\n"); - -if (sockaddr_family(pack_sockaddr_in(100,inet_aton("10.250.230.10"))) == AF_INET) { - print "ok 15\n"; -} else { - print "not ok 15\n"; -} - -eval { sockaddr_family("") }; -print (($@ =~ /^Bad arg length for Socket::sockaddr_family, length is 0, should be at least \d+/) ? "ok 16\n" : "not ok 16\n"); - -if ($^O eq 'linux') { - # see if we can handle abstract sockets - my $test_abstract_socket = chr(0) . '/org/perl/hello'. chr(0) . 'world'; - my $addr = sockaddr_un ($test_abstract_socket); - my ($path) = sockaddr_un ($addr); - if ($test_abstract_socket eq $path) { - print "ok 17\n"; - } - else { - $path =~ s/\0/\\0/g; - print "# got <$path>\n"; - print "not ok 17\n"; - } - - # see if we calculate the address structure length correctly - if (length ($test_abstract_socket) + 2 == length $addr) { - print "ok 18\n"; - } else { - print "# got ".(length $addr)."\n"; - print "not ok 18\n"; - } - -} else { - # doesn't have abstract socket support - print "ok 17 - skipped on this platform\n"; - print "ok 18 - skipped on this platform\n"; -} - -if($Config{d_inetntop} && $Config{d_inetaton}){ - print ((inet_ntop(AF_INET, inet_pton(AF_INET, "10.20.30.40")) eq "10.20.30.40") ? "ok 19\n" : "not ok 19\n"); - print ((inet_ntop(AF_INET, inet_aton("10.20.30.40")) eq "10.20.30.40") ? "ok 20\n" : "not ok 20\n"); - if(defined eval { AF_INET6() } ) { - print (lc(inet_ntop(AF_INET6, inet_pton(AF_INET6, "2001:503:BA3E::2:30")) eq "2001:503:ba3e::2:30") ? "ok 21\n" : "not ok 21\n"); - } - else { - print "ok 21 - skipped - no AF_INET6\n"; - } -} else { - # no IPv6 - print "ok $_ - skipped on this platform\n" for 19 .. 21; -} - -if(defined eval { AF_INET6() } ) { - my $sin6 = pack_sockaddr_in6(0x1234, "0123456789abcdef", 0, 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] == 0; - 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; -} |