Date: Thu, 3 Oct 2002 12:55:15 -0700 From: "Crist J. Clark" <crist.clark@attbi.com> To: Artem Okounev <aokounev@yahoo.com> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: inet_aton() Bug or feature? Message-ID: <20021003195515.GA92263@blossom.cjclark.org> In-Reply-To: <1136947159.20021003160026@yahoo.com> References: <1136947159.20021003160026@yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Oct 03, 2002 at 04:00:26PM +0300, Artem Okounev wrote: > To my great surprise I found out that: > ping 192.168.0.26, > ping 192.168.0.032, > and even ping 192.168.0.0x1a - all correct commands doing > the same thing: pinging 192.168.0.26. Yep. > That was my problem. IP addresses was stored in text file in > the form of 192.168.000.032, and after issuing command: arp > - -s 192.168.000.032 xx:xx:xx:xx:xx:xx (which actually was > treated as arp -s 192.168.0.26) I had a great headache. That should be pretty easy to fix in your script. > After some investigation I found that both ping and arp use > inet_aton() libc call to interpret their command arguments > into network format. Futher, inet_aton() uses > strtoul(c,&endptr, 0) for each octet in IP address to > convert string representation of number to unsigned long. > > Why not to use strtoul(x, x, 10) and fix aforementioned > confusing thing with arp/ping/...? Does anybody write > command arguments to ping using octal or hex format :)? > > I am not hacker. Just curious. This is a feature not a bug since it is documented in inet_aton(3), All numbers supplied as ``parts'' in a `.' notation may be decimal, octal, 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). People use this notation all of the time, # ifconfig if0 172.16.1.10 netmask 0xffffff00 ^^^^^^^^^^ -- 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-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021003195515.GA92263>