Re: Re: gethostbyname("1.1.1") returns 1.1.0.1 ????
by pg (Canon) on Mar 06, 2003 at 03:25 UTC
|
ping 127.1
and it would ping 127.0.0.1 for you. | [reply] |
Re: Re: gethostbyname("1.1.1") returns 1.1.0.1 ????
by jdporter (Paladin) on Mar 06, 2003 at 06:04 UTC
|
| [reply] |
|
|
Although it is possible that I am not understanding your point, I believe your correction is incorrect.
127.1 is 127.0.0.1. There is no range. 127.1.1 is 127.1.0.1. Again, there is no range. (Well, to be exact, there is a range of 1) The spec allows zero's before the last to be left out as a convenient expression form, not as a method of defining subnet's or 'range'. IPv6 has a similar form that allows a single '::' to be specified within the address that indicates that all missing numbers at this location are 0. Again, it is a convenient expression form, and nothing more.
| [reply] |
|
|
| [reply] [d/l] [select] |
|
|
|
|
|
|
|
Re: Re: gethostbyname("1.1.1") returns 1.1.0.1 ????
by Mr_Person (Hermit) on Mar 06, 2003 at 16:19 UTC
|
That's very interesting, I hadn't heard about that before. Just out of curiosity, do you happen to know the RFC (or whatever kind of document it is) that says all the different ways you can represent an IP address? | [reply] |
|
|
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:
- 127.1 gets translated to binary and becomes 0111111100000001
- The 24 bit netmask tells us that the host part is the last 8 bits, or 00000001
- That leaves the other 24 bits for the network part, padded with zeros we get 011111110000000000000000
- Stick these back together and you get 01111111000000000000000000000001
- Split this long binary number into 4 bytes, and convert them back to decimal, and it leaves you with 127.0.0.1
| [reply] |
|
|
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 | [reply] [d/l] [select] |