[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#183814: libc6: getaddrinfo can't parse all forms of numeric ip addresses



Greg Stark <gsstark@mit.edu> writes:

> Actually skimming RFC 2553 (I don't have a copy of the posix spec) the
> only description I see of the input is:

>>  A non-NULL nodename string can be either a node name or a numeric host
>>  address string (i.e., a dotted-decimal IPv4 address or an IPv6 hex
>>  address).

> "a dotted-decimal IPv4 address" in the most general sense could easily
> be taken to mean all the "bizarre" forms I mentioned. In reality they're
> not so bizarre and there aren't lots of different variations just one.

I stand corrected.  POSIX continues to allow all of the addresses allowed
by inet_addr as long as the family is AF_INET, not AF_INET6.  I wasn't
able to check from home, but now that I'm at work, here's the relevant
text from the latest POSIX standard.

Under getaddrinfo():

    If the nodename argument is not null, it can be a descriptive name or
    can be an address string. If the specified address family is AF_INET,
    AF_INET6, or AF_UNSPEC, valid descriptive names include host names. If
    the specified address family is AF_INET or AF_UNSPEC, address strings
    using Internet standard dot notation as specified in inet_addr() are
    valid.  If the specified address family is AF_INET6 or AF_UNSPEC,
    standard IPv6 text forms described in inet_ntop() are valid.

Under inet_addr():

    Values specified using IPv4 dotted decimal notation take one of the
    following forms:

    a.b.c.d

        When four parts are specified, each shall be interpreted as a byte
        of data and assigned, from left to right, to the four bytes of an
        Internet address.

    a.b.c

        When a three-part address is specified, the last part shall be
        interpreted as a 16-bit quantity and placed in the rightmost 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

        When a two-part address is supplied, the last part shall be
        interpreted as a 24-bit quantity and placed in the rightmost three
        bytes of the network address. This makes the two-part address
        format convenient for specifying Class A network addresses as
        "net.host".

    a

        When only one part is given, the value shall be stored directly in
        the network address without any byte rearrangement.

    All numbers supplied as parts in IPv4 dotted decimal notation may be
    decimal, octal, or hexadecimal, as specified in the ISO C standard
    (that is, a leading 0x or 0X implies hexadecimal; otherwise, a leading
    '0' implies octal; otherwise, the number is interpreted as decimal).

Apologies for the misinformation.

-- 
Russ Allbery (rra@stanford.edu)             <http://www.eyrie.org/~eagle/>



Reply to: