[ID 20001120.002] [PATCH] io_sock.t fails without 'localhost'
authorCasey Tweten <crt@kiski.net>
Mon, 20 Nov 2000 11:36:11 +0000 (06:36 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Wed, 22 Nov 2000 21:12:35 +0000 (21:12 +0000)
Message-Id: <200011201636.LAA07227@home.kiski.net>

p4raw-id: //depot/perl@7807

t/lib/io_sock.t

index 5a8e16c..45c16c2 100755 (executable)
@@ -70,17 +70,15 @@ if($pid = fork()) {
 
 } elsif(defined $pid) {
 
-    # This can fail if localhost is undefined or the
-    # special 'loopback' address 127.0.0.1 is not configured
-    # on your system. (/etc/rc.config.d/netconfig on HP-UX.)
-    # As a shortcut (not recommended) you could change 'localhost'
-    # here to be the name of this machine eg 'myhost.mycompany.com'.
-
     $sock = IO::Socket::INET->new(PeerPort => $port,
                                  Proto => 'tcp',
                                  PeerAddr => 'localhost'
                                 )
-       or die "$! (maybe your system does not have the 'localhost' address defined)";
+         || IO::Socket::INET->new(PeerPort => $port,
+                                 Proto => 'tcp',
+                                 PeerAddr => '127.0.0.1'
+                                )
+       or die "$! (maybe your system does not have a localhost at all, 'localhost' or 127.0.0.1)";
 
     $sock->autoflush(1);
 
@@ -114,7 +112,8 @@ if($pid = fork()) {
     $listen->close;
 } elsif (defined $pid) {
     # child, try various ways to connect
-    $sock = IO::Socket::INET->new("localhost:$port");
+    $sock = IO::Socket::INET->new("localhost:$port")
+         || IO::Socket::INET->new("127.0.0.1:$port");
     if ($sock) {
        print "not " unless $sock->connected;
        print "ok 6\n";
@@ -151,7 +150,9 @@ if($pid = fork()) {
     sleep(1);
 
     $sock = IO::Socket->new(Domain => AF_INET,
-                            PeerAddr => "localhost:$port");
+                            PeerAddr => "localhost:$port")
+         || IO::Socket->new(Domain => AF_INET,
+                            PeerAddr => "127.0.0.1:$port");
     if ($sock) {
        $sock->print("ok 11\n");
        $sock->print("quit\n");
@@ -166,7 +167,10 @@ if($pid = fork()) {
 # Then test UDP sockets
 $server = IO::Socket->new(Domain => AF_INET,
                           Proto  => 'udp',
-                          LocalAddr => 'localhost');
+                          LocalAddr => 'localhost')
+       || IO::Socket->new(Domain => AF_INET,
+                          Proto  => 'udp',
+                          LocalAddr => '127.0.0.1');
 $port = $server->sockport;
 
 if ($^O eq 'mpeix') {
@@ -179,7 +183,9 @@ if ($^O eq 'mpeix') {
     } elsif (defined($pid)) {
         #child
         $sock = IO::Socket::INET->new(Proto => 'udp',
-                                      PeerAddr => "localhost:$port");
+                                      PeerAddr => "localhost:$port")
+             || IO::Socket::INET->new(Proto => 'udp',
+                                      PeerAddr => "127.0.0.1:$port");
         $sock->send("ok 12\n");
         sleep(1);
         $sock->send("ok 12\n");  # send another one to be sure