[erlang-questions] is inet:gethostbyname( IP ) correct?
Roberto Aloi
roberto.aloi@REDACTED
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:
*/a/*.*/b/*.*/c/*.*/d/*
*/a/*.*/b/*.*/c/*
*/a/*.*/b/*
*/a/*
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
Internet address.
* */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
128.*/net/*.*/host/*.
* */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
*/net/*.*/host/*.
* */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).
Sources:
http://www.ietf.org/rfc/rfc3493.txt
http://uw714doc.sco.com/en/man/html.3N/inet.3N.html
Best regards,
Roberto Aloi
Erlang Training and Consulting Ltd.
http://www.erlang-consulting.com
http://aloiroberto.wordpress.com
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' ).
> {ok,{hostent,"12.27",[],inet,4,[{12,0,0,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 '12.0.0.27'?
>
> thanks
>
More information about the erlang-questions
mailing list