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