Commit | Line | Data |
fedf0971 |
1 | #!./perl -w |
2 | |
3 | BEGIN { |
67b60da2 |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | require Config; import Config; |
7 | if ($Config{'extensions'} !~ /\bSocket\b/ && |
8 | !(($^O eq 'VMS') && $Config{d_socket})) { |
9 | print "1..0 # Test uses Socket, Socket not built\n"; |
10 | exit 0; |
11 | } |
fedf0971 |
12 | } |
13 | |
d37f6f5f |
14 | BEGIN { $| = 1; print "1..7\n"; } |
fedf0971 |
15 | |
16 | END {print "not ok 1\n" unless $loaded;} |
17 | |
18 | use Net::hostent; |
19 | |
20 | $loaded = 1; |
21 | print "ok 1\n"; |
22 | |
23 | # test basic resolution of localhost <-> 127.0.0.1 |
24 | use Socket; |
25 | |
26 | my $h = gethost('localhost'); |
67b60da2 |
27 | print +(defined $h ? '' : 'not ') . "ok 2\n"; |
fedf0971 |
28 | my $i = gethostbyaddr(inet_aton("127.0.0.1")); |
67b60da2 |
29 | print +(!defined $i ? 'not ' : '') . "ok 3\n"; |
fedf0971 |
30 | |
31 | print "not " if inet_ntoa($h->addr) ne "127.0.0.1"; |
67b60da2 |
32 | print "ok 4\n"; |
fedf0971 |
33 | |
34 | print "not " if inet_ntoa($i->addr) ne "127.0.0.1"; |
67b60da2 |
35 | print "ok 5\n"; |
fedf0971 |
36 | |
37 | # need to skip the name comparisons on Win32 because windows will |
38 | # return the name of the machine instead of "localhost" when resolving |
39 | # 127.0.0.1 or even "localhost" |
40 | |
d26aeb84 |
41 | # VMS returns "LOCALHOST" under tcp/ip services V4.1 ECO 2, possibly others |
84bf2719 |
42 | # OS/390 returns localhost.YADDA.YADDA |
d26aeb84 |
43 | |
2986a63f |
44 | if ($^O eq 'MSWin32' or $^O eq 'NetWare' or $^O eq 'cygwin') { |
67b60da2 |
45 | print "ok $_ # skipped on win32\n" for (6,7); |
fedf0971 |
46 | } else { |
c9491a76 |
47 | my $in_alias; |
48 | unless ($h->name =~ /^localhost(?:\..+)?$/i) { |
49 | foreach (@{$h->aliases}) { |
50 | if (/^localhost(?:\..+)?$/i) { |
51 | $in_alias = 1; |
52 | last; |
53 | } |
54 | } |
55 | print "not " unless $in_alias; |
56 | } # Else we found it as the hostname |
57 | print "ok 6 # ",$h->name, " ", join (",", @{$h->aliases}), "\n"; |
fedf0971 |
58 | |
c9491a76 |
59 | if ($in_alias) { |
60 | # If we found it in the aliases before, expect to find it there again. |
61 | foreach (@{$h->aliases}) { |
62 | if (/^localhost(?:\..+)?$/i) { |
63 | undef $in_alias; # This time, clear the flag if we see "localhost" |
64 | last; |
65 | } |
66 | } |
67 | print "not " if $in_alias; |
68 | } else { |
69 | print "not " unless $i->name =~ /^localhost(?:\..+)?$/i; |
70 | } |
71 | print "ok 7 # ",$h->name, " ", join (",", @{$h->aliases}), "\n"; |
fedf0971 |
72 | } |