PATCH: untaint method for IO::Handle, 5.003_06 version
[p5sagit/p5-mst-13.2.git] / t / lib / socket.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib' if -d '../lib';
6     require Config; import Config;
7     if ($Config{'extensions'} !~ /\bSocket\b/ && 
8         !(($^O eq 'VMS') && $Config{d_socket})) {
9         print "1..0\n";
10         exit 0;
11     }
12 }
13         
14 use Socket;
15
16 print "1..6\n";
17
18 if (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);
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");
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 }
39 else {
40         print "# $!\n";
41         print "not ok 1\n";
42 }
43
44 if( 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);
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");
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 }
65 else {
66         print "# $!\n";
67         print "not ok 4\n";
68 }