Date: Mon, 12 Aug 2002 20:23:57 -0700 From: "Crist J. Clark" <crist.clark@attbi.com> To: Antoine Beaupre <anarcat@anarcat.ath.cx> Cc: freebsd-arch@FreeBSD.ORG Subject: Re: implementation differences between inet_aton() and inet_pton() Message-ID: <20020813032357.GA1675@blossom.cjclark.org> In-Reply-To: <3A565436-ABC5-11D6-BAC6-0050E4A0BB3F@anarcat.ath.cx>
index | next in thread | previous in thread | raw e-mail
On Fri, Aug 09, 2002 at 02:24:22PM -0400, Antoine Beaupre wrote:
> Hi
>
> I just stumbled upon some differences between the results given by
> inet_aton() and inet_pton().
>
> inet_aton() converts substrings to numbers using strtoul(). This means
> that an address like "127.0x0.0.01" will be parsed as "127.0.0.1".
>
> On the other hand, inet_pton() parses the number directly, using a
> clever hack:
>
> u_int new = *tp * 10 + (pch - digits);
>
> This assumes the number is in base 10. This means that an address like
> "127.0x0.0.01" will result in a parse error. (more precisely: 0 if the
> address wasn't parseable in the specified address family).
>
> Is this difference there by design or accident?
I think I went through this a few months ago when I noticed that
"127.0x0.0.01" and "127.1" don't work with inet_pton(3).
> In either case it should be documented how each function parses the
> numbers, because it is rather important.
Did you read the whole page? inet_pton(3) says,
STANDARDS
The inet_ntop() and inet_pton() functions conform to X/Open Networking
Services Issue 5.2 (``XNS5.2''). Note that inet_pton() does not accept
1-, 2-, or 3-part dotted addresses; all four parts must be specified and
are interpreted only as decimal values. This is a narrower input set
than that accepted by inet_aton().
--
Crist J. Clark | cjclark@alum.mit.edu
| cjclark@jhu.edu
http://people.freebsd.org/~cjc/ | cjc@freebsd.org
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020813032357.GA1675>
