Tests to check cp() doesn't drop set[eu]id bits.
[p5sagit/p5-mst-13.2.git] / lib / Net / Ping / t / 300_ping_stream.t
1 BEGIN {
2   if ($ENV{PERL_CORE}) {
3     unless ($ENV{PERL_TEST_Net_Ping}) {
4       print "1..0 # Skip: network dependent test\n";
5         exit;
6     }
7     chdir 't' if -d 't';
8     @INC = qw(../lib);
9   }
10   unless (eval "require Socket") {
11     print "1..0 \# Skip: no Socket\n";
12     exit;
13   }
14   if (my $port = getservbyname('echo', 'tcp')) {
15     socket(*ECHO, &Socket::PF_INET(), &Socket::SOCK_STREAM(), (getprotobyname 'tcp')[2]);
16     unless (connect(*ECHO, scalar &Socket::sockaddr_in($port, &Socket::inet_aton("localhost")))) {
17       print "1..0 \# Skip: loopback tcp echo service is off ($!)\n";
18       exit;
19     }
20     close (*ECHO);
21   } else {
22     print "1..0 \# Skip: no echo port\n";
23     exit;
24   }
25 }
26
27 # Test of stream protocol using loopback interface.
28 #
29 # NOTE:
30 #   The echo service must be enabled on localhost
31 #   to really test the stream protocol ping.  See
32 #   the end of this document on how to enable it.
33
34 use Test;
35 use Net::Ping;
36 plan tests => 22;
37
38 my $p = new Net::Ping "stream";
39
40 # new() worked?
41 ok !!$p;
42
43 # Attempt to connect to the echo port
44 ok ($p -> ping("localhost"));
45
46 # Try several pings while it is connected
47 for (1..20) {
48   select (undef,undef,undef,0.1);
49   ok $p -> ping("localhost");
50 }
51
52 __END__
53
54 A simple xinetd configuration to enable the echo service can easily be made.
55 Just create the following file before restarting xinetd:
56
57 /etc/xinetd.d/echo:
58
59 # description: An echo server.
60 service echo
61 {
62         type            = INTERNAL
63         id              = echo-stream
64         socket_type     = stream
65         protocol        = tcp
66         user            = root
67         wait            = no
68         disable         = no
69 }
70
71
72 Or if you are using inetd, before restarting, add
73 this line to your /etc/inetd.conf:
74
75 echo   stream  tcp     nowait  root    internal