| Summary: | inet_aton() may fail for some addresses (e.g. 204.08.126.0) | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Pavlin Ivanov Radoslavov <pavlin> |
| Component: | misc | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | CC: | pavlin |
| Priority: | Normal | ||
| Version: | 4.0-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
This is documented in the inet_aton() man page:
All numbers supplied as ``parts'' in a `.' notation may be decimal, oc-
tal, or hexadecimal, as specified in the C language (i.e., a leading 0x
or 0X implies hexadecimal; otherwise, a leading 0 implies octal; other-
wise, the number is interpreted as decimal).
Many people think that inet_aton() only takes dotted decimal, but
it actually also accepts hex and octal and addresses with less than
4 dots.
Bill
State Changed From-To: open->closed The 4.0 behavior agrees with the man page and has been the documented behavior since at least 4.3-Reno. The bug was in the previous versions. This is consistent with other OS's as well (e.g. Solaris). |
inet_aton() may fail for some IPv4 addresses that may look OK. E.g. such address is 204.08.126.0 (note the '0' in front of '8', i.e. "08" is OK in base-10, but not valid in base-8 (a fact that triggers the error because of the particular implemetation which uses strtoul() Fix: The problem is in the inet_aton() implementation in libc: /usr/src/lib/libc/net/inet_addr.c Older FreeBSD versions (e.g. FreeBSD-3.2) are OK, so one possible solution is to use the implementation from those older systems instead of the FreeBSD-4.0 solution. How-To-Repeat: Compile and execute the following code: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main() { struct in_addr in_addr; char *s; s = "204.08.126.0"; if (inet_aton(s, &in_addr) == 1) printf("OK\n"); else printf("ERROR\n"); exit (0); }