http://qs321.pair.com?node_id=126485

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

Hello,
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.

Hotshot

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.0.1; 1.1 to 1.0.0.1.

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

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

     - ask

    -- 
    ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
    
Re: gethostbyname
by mce (Curate) on Nov 20, 2001 at 18:56 UTC
    Hi,

    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. www.perlmonks.org).

    A domain administrator can put in hostname-address pairs for addresses that don't exist. vroom or the administrator for perlmonks could put in "nosuchhost.perlmonks.org" 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