This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: untaint method for IO::Handle, 5.003_06 version
[perl5.git] / t / lib / socket.t
CommitLineData
37120919
AD
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib' if -d '../lib';
6 require Config; import Config;
c07a80fd 7 if ($Config{'extensions'} !~ /\bSocket\b/ &&
3149255e 8 !(($^O eq 'VMS') && $Config{d_socket})) {
2af9ad4a 9 print "1..0\n";
37120919
AD
10 exit 0;
11 }
12}
13
14use Socket;
15
16print "1..6\n";
17
18if (socket(T,PF_INET,SOCK_STREAM,6)) {
19 print "ok 1\n";
20
21 if (connect(T,pack_sockaddr_in(7,inet_aton("localhost")))){
22 print "ok 2\n";
23
24 print "# Connected to ",
25 inet_ntoa((unpack_sockaddr_in(getpeername(T)))[1]),"\n";
26
27 syswrite(T,"hello",5);
962dce22
PP
28 $read = sysread(T,$buff,10); # Connection may be granted, then closed!
29 print(($read == 0 || $buff eq "hello") ? "ok 3\n" : "not ok 3\n");
37120919
AD
30 }
31 else {
32 print "# You're allowed to fail tests 2 and 3 if.\n";
33 print "# The echo service has been disabled.\n";
34 print "# $!\n";
35 print "ok 2\n";
36 print "ok 3\n";
37 }
38}
39else {
40 print "# $!\n";
41 print "not ok 1\n";
42}
43
44if( socket(S,PF_INET,SOCK_STREAM,6) ){
45 print "ok 4\n";
46
47 if (connect(S,pack_sockaddr_in(7,INADDR_LOOPBACK))){
48 print "ok 5\n";
49
50 print "# Connected to ",
51 inet_ntoa((unpack_sockaddr_in(getpeername(S)))[1]),"\n";
52
53 syswrite(S,"olleh",5);
962dce22
PP
54 $read = sysread(S,$buff,10); # Connection may be granted, then closed!
55 print(($read == 0 || $buff eq "olleh") ? "ok 6\n" : "not ok 6\n");
37120919
AD
56 }
57 else {
58 print "# You're allowed to fail tests 5 and 6 if.\n";
59 print "# The echo service has been disabled.\n";
60 print "# $!\n";
61 print "ok 5\n";
62 print "ok 6\n";
63 }
64}
65else {
66 print "# $!\n";
67 print "not ok 4\n";
68}