summaryrefslogtreecommitdiff
path: root/lib/Net/Ping/t/300_ping_stream.t
blob: 270650a2c31a63fa8dbc1768a18c65382f4f3f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
BEGIN {
  if ($ENV{PERL_CORE}) {
    unless ($ENV{PERL_TEST_Net_Ping}) {
      print "1..0 # Skip: network dependent test\n";
        exit;
    }
    chdir 't' if -d 't';
    @INC = qw(../lib);
  }
  unless (eval "require Socket") {
    print "1..0 \# Skip: no Socket\n";
    exit;
  }
  unless (getservbyname('echo', 'udp')) {
    print "1..0 \# Skip: no echo port\n";
    exit;
  }
}

# Test of stream protocol using loopback interface.
#
# NOTE:
#   The echo service must be enabled on localhost
#   to really test the stream protocol ping.

use Test;
use Net::Ping;
plan tests => 12;

my $p = new Net::Ping "stream";

# new() worked?
ok !!$p;

# Attempt to connect to the echo port
if ($p -> ping("localhost")) {
  ok 1;
  # Try several pings while it is connected
  for (1..10) {
    ok $p -> ping("localhost");
  }
} else {
  # Echo port is off, skip the tests
  for (2..12) { skip "Local echo port is off", 1; }
  exit;
}

__END__

A simple xinetd configuration to enable the echo service can easily be made.
Just create the following file before restarting xinetd:

/etc/xinetd.d/echo:

# description: echo service
service echo
{
        socket_type             = stream
        wait                    = no
        user                    = root
        server                  = /bin/cat
        disable                 = no
}

Or if you are using inetd, before restarting, add
this line to your /etc/inetd.conf:

echo   stream  tcp     nowait  root    internal