11 require Config; import Config;
12 if ($Config{'extensions'} !~ /\bSocket\b/ &&
13 !(($^O eq 'VMS') && $Config{d_socket}))
15 plan skip_all => "Test uses Socket, Socket not built";
17 if ($^O eq 'MacOS' || ($^O eq 'irix' && $Config{osvers} == 5)) {
18 plan skip_all => "Test relies on resolution of localhost, fails on $^O ($Config{osvers})";
22 use Test::More tests => 7;
24 BEGIN { use_ok 'Net::hostent' }
26 # Remind me to add this to Test::More.
32 # test basic resolution of localhost <-> 127.0.0.1
35 my $h = gethost('localhost');
37 skip "Can't resolve localhost and you don't have /etc/hosts", 6
38 if (!defined($h) && !-e '/etc/hosts');
40 ok(defined $h, "gethost('localhost')") ||
41 DIE("Can't continue without working gethost: $!");
43 is( inet_ntoa($h->addr), "127.0.0.1", 'addr from gethost' );
45 my $i = gethostbyaddr(inet_aton("127.0.0.1"));
46 ok(defined $i, "gethostbyaddr('127.0.0.1')") ||
47 DIE("Can't continue without working gethostbyaddr: $!");
49 is( inet_ntoa($i->addr), "127.0.0.1", 'addr from gethostbyaddr' );
51 # need to skip the name comparisons on Win32 because windows will
52 # return the name of the machine instead of "localhost" when resolving
53 # 127.0.0.1 or even "localhost"
55 # - VMS returns "LOCALHOST" under tcp/ip services V4.1 ECO 2, possibly others
56 # - OS/390 returns localhost.YADDA.YADDA
59 skip "Windows will return the machine name instead of 'localhost'", 2
60 if $^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'cygwin';
62 print "# name = " . $h->name . ", aliases = " . join (",", @{$h->aliases}) . "\n";
65 unless ($h->name =~ /^localhost(?:\..+)?$/i) {
66 foreach (@{$h->aliases}) {
67 if (/^localhost(?:\..+)?$/i) {
78 # If we found it in the aliases before, expect to find it there again.
79 foreach (@{$h->aliases}) {
80 if (/^localhost(?:\..+)?$/i) {
81 # This time, clear the flag if we see "localhost"
89 like( $i->name, qr/^localhost(?:\..+)?$/i );
93 print "# " . $h->name . " " . join (",", @{$h->aliases}) . "\n";