in reply to Re: Re: gethostbyname("1.1.1") returns 1.1.0.1 ????
in thread gethostbyname("1.1.1") returns 1.1.0.1 ????

I don't think there is an RFC that explicitly explains this, the reason it works is that if you take the address 127.1/24, the netmask specifies that the first 24 bits are the network address and the rest are the host address, the 127 falls within the network address part, setting the appropriate bits to one, and leaves all the other bits in the network part (even the unspecified ones) as zeros, since there is no third state that can represent the undefined value.

So, the way I understand it, it works something like this:

  • Comment on Re: Re: Re: gethostbyname("1.1.1") returns 1.1.0.1 ????

Replies are listed 'Best First'.
Re: gethostbyname("1.1.1") returns 1.1.0.1 ????
by Abigail-II (Bishop) on Mar 07, 2003 at 00:00 UTC
    I'm pretty sure that's not the reason. First, addresses like 127.1 work even if you do not give a a netmask. Secondly, the notation was used even before we had classless networks, and we were still dealing with A, B, C and D class networks.

    Note that many utilities also accept addresses in hex, octal, or even a combination of hex, octal and decimal:

    $ ping -c 1 0x42.047.54.0x1b # www.perlmonks.org PING 0x42.047.54.0x1b (66.39.54.27): 56 data bytes 64 bytes from 66.39.54.27: icmp_seq=0 ttl=244 time=114.3 ms --- 0x42.047.54.0x1b ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 114.3/114.3/114.3 ms $

    Abigail