Tests to check cp() doesn't drop set[eu]id bits.
[p5sagit/p5-mst-13.2.git] / lib / 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 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 }
9c36735d 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")))) {
03550e9d 17 print "1..0 \# Skip: loopback tcp echo service is off ($!)\n";
9c36735d 18 exit;
19 }
20 close (*ECHO);
21 } else {
ddbbf559 22 print "1..0 \# Skip: no echo port\n";
23 exit;
24 }
505f3f16 25}
26
27# Test of stream protocol using loopback interface.
28#
29# NOTE:
30# The echo service must be enabled on localhost
9c36735d 31# to really test the stream protocol ping. See
32# the end of this document on how to enable it.
505f3f16 33
34use Test;
35use Net::Ping;
9c36735d 36plan tests => 22;
505f3f16 37
38my $p = new Net::Ping "stream";
39
40# new() worked?
41ok !!$p;
42
43# Attempt to connect to the echo port
9c36735d 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");
505f3f16 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
9c36735d 59# description: An echo server.
505f3f16 60service echo
61{
9c36735d 62 type = INTERNAL
63 id = echo-stream
64 socket_type = stream
65 protocol = tcp
66 user = root
67 wait = no
68 disable = no
505f3f16 69}
49afa5f6 70
9c36735d 71
49afa5f6 72Or if you are using inetd, before restarting, add
73this line to your /etc/inetd.conf:
74
75echo stream tcp nowait root internal