Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw


by hotshot (Prior)
on Nov 20, 2001 at 13:03 UTC ( #126485=perlquestion: print w/replies, xml ) Need Help??

hotshot has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone explain why does gethostbyname returns that an address of 1.1 or 1.1.1 or any other combination of numbers separated by dots, are valid hosts (it returns the array of $name, $aliases...), Is there no validation that this host realy exists.


Replies are listed 'Best First'.
Re: gethostbyname
by ask (Pilgrim) on Nov 20, 2001 at 13:21 UTC
    They are valid ways of writing ip addresses. 1.1.1 comes to; 1.1 to

    Try pinging "127.1". Or 2130706433. (127*256^3+1).

    $ ping -c 1 2130706433 PING 2130706433 ( 56 data bytes 64 bytes from icmp_seq=0 ttl=64 time=0.145 ms

     - ask

    ask bjoern hansen,   !try; do();
Re: gethostbyname
by mce (Curate) on Nov 20, 2001 at 18:56 UTC

    The way I understand it, is that perl just calls the standard c calls: gethostbyname and gethostbyaddr . The latter one returns the information which is defined in the netdb.h file (at least on solaris, but I guess this is similar on other unixes). Perl just returns the values the operating system returns, and therefore relies uppon the OS to determine the information.

    Can you tell me which OS you are running on?

    But, since I am not a code wizzard, .....
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium

Re: gethostbyname
by traveler (Parson) on Nov 20, 2001 at 21:42 UTC
    Most OSs let the administrator configure how the process of "name resolution" (converting names to addresses) takes place. Some common options, and they can be used individually or searched in some configurable order, are: a local file (e.g. HOSTS or /etc/hosts), a NIS database, or DNS the Domain Name System. The later is a distributed database of name to address (and the reverse) mappings. You may have an internal DNS and the Internet has one for its names (e.g.

    A domain administrator can put in hostname-address pairs for addresses that don't exist. vroom or the administrator for perlmonks could put in "" at some address. This might be for testing. A name could also resolve to an address of a host that was offline becuse it was failing or down for maintenance. DNS, hosts, and NIS only return the mappings. This is probably from the traditional UNIX philosophy that a tool should do one thing and do it well. If you want to see if a host exists, try to access it. ping might work if it is not blocked at a firewall, but it might not.

    HTH, --traveler

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://126485]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-05-27 03:40 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (94 votes). Check out past polls.