1 # Testing service_check method using tcp and syn protocols.
4 unless (eval "require IO::Socket") {
5 print "1..0 \# Skip: no IO::Socket\n";
8 unless (getservbyname('echo', 'tcp')) {
9 print "1..0 \# Skip: no echo port\n";
18 # I'm lazy so I'll just use IO::Socket
19 # for the TCP Server stuff instead of doing
20 # all that direct socket() junk manually.
22 plan tests => 26, ($^O eq 'MSWin32' ? (todo => [18]) :
23 $^O eq "hpux" ? (todo => [9, 18]) : ());
25 # Everything loaded fine
28 # Start a tcp listen server on ephemeral port
29 my $sock1 = new IO::Socket::INET
30 LocalAddr => "127.0.0.1",
35 # Make sure it worked.
38 # Start listening on another ephemeral port
39 my $sock2 = new IO::Socket::INET
40 LocalAddr => "127.0.0.1",
45 # Make sure it worked too.
48 my $port1 = $sock1->sockport;
51 my $port2 = $sock2->sockport;
54 # Make sure the sockets are listening on different ports.
55 ok ($port1 != $port2);
59 # This is how it should be:
60 # 127.0.0.1:$port1 - service ON
61 # 127.0.0.1:$port2 - service OFF
64 # First, we test using the "tcp" protocol.
65 # (2 seconds should be long enough to connect to loopback.)
66 my $p = new Net::Ping "tcp", 2;
71 # Disable service checking
74 # Try on the first port
75 $p->{port_num} = $port1;
77 # Make sure it is reachable
78 ok $p -> ping("127.0.0.1");
80 # Try on the other port
81 $p->{port_num} = $port2;
83 # Make sure it is reachable
84 ok $p -> ping("127.0.0.1");
88 # Enable service checking
91 # Try on the first port
92 $p->{port_num} = $port1;
94 # Make sure service is on
95 ok $p -> ping("127.0.0.1");
97 # Try on the other port
98 $p->{port_num} = $port2;
100 # Make sure service is off
101 ok !$p -> ping("127.0.0.1");
103 # test 11 just finished.
106 # Lastly, we test using the "syn" protocol.
107 $p = new Net::Ping "syn", 2;
112 # Disable service checking
113 $p->service_check(0);
115 # Try on the first port
116 $p->{port_num} = $port1;
119 if (!ok $p -> ping("127.0.0.1")) {warn "ERRNO: $!";}
121 # IP should be reachable
128 $p = new Net::Ping "syn", 2;
133 # Disable service checking
134 $p->service_check(0);
136 # Try on the other port
137 $p->{port_num} = $port2;
140 if (!ok $p -> ping("127.0.0.1")) {warn "ERRNO: $!";}
142 # IP should still be reachable
150 $p = new Net::Ping "syn", 2;
155 # Enable service checking
156 $p->service_check(1);
158 # Try on the first port
159 $p->{port_num} = $port1;
162 ok $p -> ping("127.0.0.1");
164 # Should have service on
165 ok ($p -> ack(),"127.0.0.1");
166 # No more good sockets?
172 $p = new Net::Ping "syn", 2;
177 # Enable service checking
178 $p->service_check(1);
180 # Try on the other port
181 $p->{port_num} = $port2;
184 if (!ok $p -> ping("127.0.0.1")) {warn "ERRNO: $!";}
186 # No sockets should have service on