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