3 # This program check if we are able to talk to ourself. Misconfigured
4 # systems that can't talk to their own 'hostname' was the most commonly
5 # reported libwww-failure.
10 if ( @ARGV >= 2 && $ARGV[0] eq "--port" )
13 require Sys
::Hostname
;
14 my $host = Sys
::Hostname
::hostname
();
16 my $socket = IO
::Socket
::INET
->new( PeerAddr
=> "$host:$port",
21 if ( IO
::Select
->new($socket)->can_read(1) )
24 if ( $n = sysread( $socket, $buf, 512 ) )
26 exit if $buf eq "Hi there!\n";
27 die "Seems to be talking to the wrong server at $host:$port, got \"$buf\"\n";
31 die "Immediate EOF from server at $host:$port\n";
35 die "Can't read from server at $host:$port: $!";
38 die "No response from server at $host:$port\n";
40 die "Can't connect: $@\n";
44 my $socket = IO
::Socket
::INET
->new( Listen
=> 1,
46 my $port = $socket->sockport;
47 open( CLIENT
, qq("$^X" "$0" --port
$port |) ) || die "Can't run $^X $0: $!\n";
49 if ( my $client = $socket->accept )
51 print $client "Hi there!\n";
52 close($client) || die "Can't close socket: $!";
56 warn "Test server timeout\n";
59 exit if close(CLIENT
);
60 die "Can't wait for client: $!" if $!;
61 die "The can-we-talk-to-ourself test failed.\n";