davis has asked for the wisdom of the Perl Monks concerning the following question:
The ok/not ok is a little funky because of the other stuff that my "real" code is doing, but this is a working example of the unwanted passing of a test. Can anyone see where I'm going wrong? I believe recv is supposed to return undef on failure, but it doesn't appear to.#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use Test::More tests => 1; use IO::Socket; my $expected_closed_port = 111; my $dead_socket = IO::Socket::INET->new(PeerAddr => 'localhost', PeerP +ort => $expected_closed_port, Proto => "udp"); if($dead_socket) { # It could be a UDP connection, and there's no such concept as + UP or DOWN, so we need to try sending an # empty datagram, and check for an error $dead_socket->send(""); my $foo; setsockopt( $dead_socket, SOL_SOCKET, SO_RCVTIMEO, pack('L!L!' +, +10, 0) ); my $return_value = recv($dead_socket, $foo, 1, 0); if(defined($return_value)) { ok(0, "I shouldn't be able to connect to port $expected_cl +osed_port on localhost"); } else { ok(1, "I shouldn't be able to connect to port $expected_cl +osed_port on localhost"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Proving a UDP port is closed
by marto (Cardinal) on Feb 01, 2011 at 15:27 UTC | |
|
Re: Proving a UDP port is closed
by Limbic~Region (Chancellor) on Feb 01, 2011 at 14:31 UTC | |
by gman (Friar) on Feb 01, 2011 at 14:59 UTC | |
by davis (Vicar) on Feb 01, 2011 at 15:17 UTC | |
by davis (Vicar) on Feb 01, 2011 at 14:54 UTC | |
by Limbic~Region (Chancellor) on Feb 01, 2011 at 15:00 UTC | |
by davis (Vicar) on Feb 01, 2011 at 15:11 UTC | |
by Anonymous Monk on Feb 01, 2011 at 15:29 UTC | |
|