Opened 12 years ago

Closed 4 years ago

#3884 closed bug (fixed)

short-form IP adress format broken

Reported by: marcusoverhagen Owned by: nobody
Priority: normal Milestone: R1
Component: Network & Internet Version: R1/pre-alpha1
Keywords: gsoc2017 Cc:
Blocked By: Blocking:
Platform: All

Description (last modified by marcusoverhagen)

Specifying the DNS address as 10.1 in Network preferences, and thus also in /etc/resolv.conf doesn't work. It has to be written as

"ftp 10.1" or "telnet 10.1" in Terminal doesn't work, using "ftp" or "telnet" works.

Using http://10.1 in Firefox however does work.

10.1 is a valid address. Something is wrong, please fix.

a -- 32 bits

a.b -- 8.24 bits

a.b.c -- 8.8.16 bits

a.b.c.d -- bits

Attachments (2)

0001-resolved-shorthand-ipv4-addresses-for-getaddrinfo-vi.patch (2.9 KB ) - added by a-star 4 years ago.
0001-getaddrinfo-now-accepts-shorthand-ipv4-notation.patch (1.0 KB ) - added by a-star 4 years ago.
For AF_INET inet_aton is used, inet_pton otherwise

Download all attachments as: .zip

Change History (17)

comment:1 by marcusoverhagen, 12 years ago

Description: modified (diff)

comment:2 by marcusoverhagen, 12 years ago

Summary: IP adress formatshort-form IP adress format broken

"There are four forms of the standard numbers-and-dots notation for Internet addresses"

comment:3 by diver, 10 years ago

Component: - GeneralNetwork & Internet

comment:4 by pulkomandy, 6 years ago

Support for this is available in libbind in inet_aton, but not in inet_pton which is the multi-protocol (ie. ipv6 aware) version. This makes sense, since the class notation is deprecated and was replaced by network masks which are more flexible.

However, getaddrinfo should handle both IPv6 (it does) and old IPv4 class notation. I'm not sure if it does currently.

comment:5 by a-star, 4 years ago

I was able to rectify the problem by changing the inet_pton.c file (under src/kits/network/netresolv/inet) without breaking anything. Is it acceptable or do I need to change the getaddrinfo.c file for patching this issue?

comment:6 by pulkomandy, 4 years ago

It is fine, if you are sure nothing is broken. For such changes, adding to the unit tests would be nice, in order to prevent future regressions.

comment:7 by a-star, 4 years ago

patch: 01

comment:8 by pulkomandy, 4 years ago

Actually, this is not the right solution. POSIX explicitly disallow doing this:

inet_pton must accept only addresses in the ddd.ddd.ddd.ddd format.

If the af argument of inet_pton() is AF_INET, the src string shall be in the standard IPv4 dotted-decimal form:


where "ddd" is a one to three digit decimal number between 0 and 255 (see inet_addr). The inet_pton() function does not accept other formats (such as the octal numbers, hexadecimal numbers, and fewer than four numbers that inet_addr() accepts).

So, it would seem everything is as expected: this address format is no longer supported in the default case.

comment:9 by pulkomandy, 4 years ago

patch: 10

comment:10 by a-star, 4 years ago

In comment 5, when I mentioned that I changed the inet_pton.c file, this is what I was worried about. Thanks for the review. I was wondering if changing the code for getaddrinfo to send the expanded version of short form ip address to inet_pton would be a valid patch. If not so, can you point me in the correct direction.

comment:11 by pulkomandy, 4 years ago

From POSIX documentation of 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.


And, inet_addr explicitly says that the forms mentionned here should be accepted (

So, if our getaddrinfo does not do that, it should be adjusted to handle it properly.

I think the cleanest solution would be for getaddrinfo to call inet_pton4 directly for the AF_INET family (telling it to use the inet_addr format), and inet_pton for other cases? (didn't check getaddrinfo code, so maybe that doesn't make sense).

comment:12 by a-star, 4 years ago

Will work on that and provide a patch in a few days. Currently busy working on the proposal. Shouldn't take more than 2 days.

comment:13 by axeld, 4 years ago

Owner: changed from axeld to nobody
Status: newassigned

by a-star, 4 years ago

For AF_INET inet_aton is used, inet_pton otherwise

comment:14 by a-star, 4 years ago

patch: 01

comment:15 by pulkomandy, 4 years ago

Keywords: gsoc2017 added
Resolution: fixed
Status: assignedclosed

Applied in hrev51113. Thanks!

Note: See TracTickets for help on using tickets.