6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bSocket\b/ &&
8 !(($^O eq 'VMS') && $Config{d_socket})) {
12 $has_alarm = $Config{d_alarm};
19 $has_echo = $^O ne 'MSWin32';
21 sub arm { $alarmed = 0; alarm(shift) if $has_alarm }
22 sub alarmed { $alarmed = 1 }
23 $SIG{ALRM} = 'alarmed' if $has_alarm;
25 if (socket(T,PF_INET,SOCK_STREAM,6)) {
29 my $host = $^O eq 'MacOS' ? '127.0.0.1' : 'localhost';
30 if ($has_echo && connect(T,pack_sockaddr_in(7,inet_aton($host)))){
35 print "# Connected to " .
36 inet_ntoa((unpack_sockaddr_in(getpeername(T)))[1])."\n";
39 syswrite(T,"hello",5);
43 $read = sysread(T,$buff,10); # Connection may be granted, then closed!
46 while ($read > 0 && length($buff) < 5) {
47 # adjust for fact that TCP doesn't guarantee size of reads/writes
49 $read = sysread(T,$buff,10,length($buff));
52 print(($read == 0 || $buff eq "hello") ? "ok 3\n" : "not ok 3\n");
55 print "# You're allowed to fail tests 2 and 3 if\n";
56 print "# the echo service has been disabled.\n";
57 print "# 'Interrupted system call' indicates a hanging echo service.\n";
58 print "# Error: $!\n";
59 print "ok 2 - skipped\n";
60 print "ok 3 - skipped\n";
64 print "# Error: $!\n";
68 if( socket(S,PF_INET,SOCK_STREAM,6) ){
72 if ($has_echo && connect(S,pack_sockaddr_in(7,INADDR_LOOPBACK))){
77 print "# Connected to " .
78 inet_ntoa((unpack_sockaddr_in(getpeername(S)))[1])."\n";
81 syswrite(S,"olleh",5);
85 $read = sysread(S,$buff,10); # Connection may be granted, then closed!
88 while ($read > 0 && length($buff) < 5) {
89 # adjust for fact that TCP doesn't guarantee size of reads/writes
91 $read = sysread(S,$buff,10,length($buff));
94 print(($read == 0 || $buff eq "olleh") ? "ok 6\n" : "not ok 6\n");
97 print "# You're allowed to fail tests 5 and 6 if\n";
98 print "# the echo service has been disabled.\n";
99 print "# 'Interrupted system call' indicates a hanging echo service.\n";
100 print "# Error: $!\n";
101 print "ok 5 - skipped\n";
102 print "ok 6 - skipped\n";
106 print "# Error: $!\n";
111 $SIG{__WARN__} = sub {
112 ++ $w if $_[0] =~ /^6-ARG sockaddr_in call is deprecated/ ;
115 sockaddr_in(1,2,3,4,5,6) ;
116 print ($w == 1 ? "not ok 7\n" : "ok 7\n") ;
117 use warnings 'Socket' ;
118 sockaddr_in(1,2,3,4,5,6) ;
119 print ($w == 1 ? "ok 8\n" : "not ok 8\n") ;
121 # Thest that whatever we give into pack/unpack_sockaddr retains
122 # the value thru the entire chain.
123 if((inet_ntoa((unpack_sockaddr_in(pack_sockaddr_in(100,inet_aton("10.250.230.10"))))[1])) eq '10.250.230.10') {
128 print ((inet_ntoa(inet_aton("10.20.30.40")) eq "10.20.30.40") ? "ok 10\n" : "not ok 10\n");
129 print ((inet_ntoa(v10.20.30.40) eq "10.20.30.40") ? "ok 11\n" : "not ok 11\n");
131 my ($port,$addr) = unpack_sockaddr_in(pack_sockaddr_in(100,v10.10.10.10));
132 print (($port == 100) ? "ok 12\n" : "not ok 12\n");
133 print ((inet_ntoa($addr) eq "10.10.10.10") ? "ok 13\n" : "not ok 13\n");
136 eval { inet_ntoa(v10.20.30.400) };
137 print (($@ =~ /^Wide character in Socket::inet_ntoa at/) ? "ok 14\n" : "not ok 14\n");
139 if (sockaddr_family(pack_sockaddr_in(100,inet_aton("10.250.230.10"))) == AF_INET) {
145 eval { sockaddr_family("") };
146 print (($@ =~ /^Bad arg length for Socket::sockaddr_family, length is 0, should be at least \d+/) ? "ok 16\n" : "not ok 16\n");