1BEGIN {
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
34use Test;
35use Net::Ping;
36plan tests => 22;
37
38my $p = new Net::Ping "stream";
39
40# new() worked?
41ok !!$p;
42
43# Attempt to connect to the echo port
44ok ($p -> ping("localhost"));
45
46# Try several pings while it is connected
47for (1..20) {
48  select (undef,undef,undef,0.1);
49  ok $p -> ping("localhost");
50}
51
52__END__
53
54A simple xinetd configuration to enable the echo service can easily be made.
55Just create the following file before restarting xinetd:
56
57/etc/xinetd.d/echo:
58
59# description: An echo server.
60service 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
72Or if you are using inetd, before restarting, add
73this line to your /etc/inetd.conf:
74
75echo   stream  tcp     nowait  root    internal
76