[erlang-questions] is inet:gethostbyname( IP ) correct?
Wed Oct 14 11:34:53 CEST 2009
This is due to the dot notation used in inet_addr().
Reading from the doc:
Values specified using the dot notation take one of the following forms:
Each of the four notation types are described below.
* */a/*.*/b/*.*/c/*.*/d/* notation
When four parts are specified, each is interpreted as a byte of
data and assigned, from left to right, to the four bytes of an
* */a/*.*/b/*.*/c/* notation
When a three-part address is specified, the last part is
interpreted as a 16-bit quantity and placed in the right most two
bytes of the network address. This makes the three-part address
format convenient for specifying Class B network addresses as
* */a/*.*/b/* notation
When a two-part address is supplied, the last part is interpreted
as a 24-bit quantity and placed in the right most three bytes of
the network address. This makes the two-part address format
convenient for specifying Class A network addresses as
* */a/* notation
When only one part is given, the value is stored directly in the
network address without any byte rearrangement.
All numbers supplied as parts in dot notation may be decimal, octal, or
hexadecimal, as specified in the C language (that is, a leading 0x or 0X
implies hexadecimal; otherwise, a leading 0 implies octal; otherwise,
the number is interpreted as decimal).
Erlang Training and Consulting Ltd.
Garry Hodgson wrote:
> recently, a bug in my code caused us to pass a string
> representing a floating point number to inet:gethostbyname().
> i would have expected it to return an error, but instead it
> returned an ip address, but one that made no sense to me:
> 1> inet:gethostbyname( '12.27' ).
> so my question is, is this behavior correct, and if so, what
> exactly does it mean that a lookup of '12.27' maps to '126.96.36.199'?
More information about the erlang-questions