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