3 unless ($ENV{PERL_TEST_Net_Ping}) {
4 print "1..0 # Skip: network dependent test\n";
8 unless (eval "require Socket") {
9 print "1..0 \# Skip: no Socket\n";
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";
20 print "1..0 \# Skip: no echo port\n";
25 # Test of stream protocol using loopback interface.
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.
36 my $p = new Net::Ping "stream";
41 # Attempt to connect to the echo port
42 ok ($p -> ping("localhost"));
44 # Try several pings while it is connected
46 select (undef,undef,undef,0.1);
47 ok $p -> ping("localhost");
52 A simple xinetd configuration to enable the echo service can easily be made.
53 Just create the following file before restarting xinetd:
57 # description: An echo server.
70 Or if you are using inetd, before restarting, add
71 this line to your /etc/inetd.conf:
73 echo stream tcp nowait root internal