From owner-freebsd-hackers Thu Oct 3 13: 7: 6 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7625C37B401 for ; Thu, 3 Oct 2002 13:07:04 -0700 (PDT) Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) by mx1.FreeBSD.org (Postfix) with ESMTP id AF26643E42 for ; Thu, 3 Oct 2002 13:07:00 -0700 (PDT) (envelope-from crist.clark@attbi.com) Received: from blossom.cjclark.org ([12.234.91.48]) by rwcrmhc52.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20021003195518.TULG9928.rwcrmhc52.attbi.com@blossom.cjclark.org>; Thu, 3 Oct 2002 19:55:18 +0000 Received: from blossom.cjclark.org (localhost. [127.0.0.1]) by blossom.cjclark.org (8.12.3/8.12.3) with ESMTP id g93JtHWn092525; Thu, 3 Oct 2002 12:55:17 -0700 (PDT) (envelope-from crist.clark@attbi.com) Received: (from cjc@localhost) by blossom.cjclark.org (8.12.3/8.12.3/Submit) id g93JtGYF092524; Thu, 3 Oct 2002 12:55:16 -0700 (PDT) X-Authentication-Warning: blossom.cjclark.org: cjc set sender to crist.clark@attbi.com using -f Date: Thu, 3 Oct 2002 12:55:15 -0700 From: "Crist J. Clark" To: Artem Okounev Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: inet_aton() Bug or feature? Message-ID: <20021003195515.GA92263@blossom.cjclark.org> Reply-To: "Crist J. Clark" References: <1136947159.20021003160026@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1136947159.20021003160026@yahoo.com> User-Agent: Mutt/1.4i X-URL: http://people.freebsd.org/~cjc/ Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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