From owner-freebsd-net@FreeBSD.ORG Tue Feb 26 11:50:46 2008 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AA5171065938 for ; Tue, 26 Feb 2008 11:50:46 +0000 (UTC) (envelope-from ithilgore.fbsd@gmail.com) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.185]) by mx1.freebsd.org (Postfix) with ESMTP id A176413DEE2 for ; Tue, 26 Feb 2008 09:54:56 +0000 (UTC) (envelope-from ithilgore.fbsd@gmail.com) Received: by nf-out-0910.google.com with SMTP id b2so1212114nfb.33 for ; Tue, 26 Feb 2008 01:54:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=P3/yHwFYA37Onub2ZN3NKPNzIsK+XVdWi73NOC9pBmU=; b=LNmzbIBGQKmv8WPyFPIoDS4GBP3YaGbtUuVdgGYTAbCvGOFTAy7nsZ2T2RpZBvE4T74LoIutZ3NlzxWtRStI86yjwQgIIttd8IIwIxNb8JlNJ7iVMj1Tw0M+lmSqbxllKfCLFCEHhq0oTWg6b7tEsI8yelKHJIdV1ZYcKCGcHZ0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=OaYcn/I6YPIau82B6SSTz0YAYFbFAfcVH09xVK8q9s4ebNsrNWyUJWrp9V8aBMnQcespsIrFQWjgXEAOVF/Iloa636lD3PUTKUl4F0Oh+1mALGkqUNjunie2mQcJgEXfrTOBFtKUYBxtYxSW3Y2TgOEvWy7p9PZYmqbyhvFH4So= Received: by 10.78.107.8 with SMTP id f8mr2164651huc.40.1204019695250; Tue, 26 Feb 2008 01:54:55 -0800 (PST) Received: from ?10.0.0.12? ( [62.1.229.152]) by mx.google.com with ESMTPS id e9sm9015384muf.0.2008.02.26.01.54.53 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 26 Feb 2008 01:54:54 -0800 (PST) Message-ID: <47C46DCF.6050202@gmail.com> Date: Tue, 26 Feb 2008 11:51:43 -0800 From: ithilgore User-Agent: Thunderbird 2.0.0.9 (X11/20071212) MIME-Version: 1.0 To: Giorgos Keramidas References: <47BFF17B.5080205@gmail.com> <47BFF74E.4010608@gmail.com> <20080226040438.GA2676@kobe.laptop> In-Reply-To: <20080226040438.GA2676@kobe.laptop> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-net@freebsd.org Subject: Re: question about change in inet_ntoa.c X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Feb 2008 11:50:48 -0000 Giorgos Keramidas wrote: > On 2008-02-23 02:37, ithilgore wrote: > >> ithilgore wrote: >> >>> I was looking at the differences between some old FreeBSD code >>> and the one of 7.0-RC1 and was wondering about a change >>> in inet_ntoa.c >>> >>> /***** 7.0-RC1 **************/ >>> >>> sprintf(buf, "%d.%d.%d.%d", >>> ucp[0] & 0xff, >>> ucp[1] & 0xff, >>> ucp[2] & 0xff, >>> ucp[3] & 0xff); >>> >>> >>> /****** 4.11-RELEASE ***********/ >>> >>> >>> static const char fmt[] = "%u.%u.%u%u"; >>> if ((size_t)snprintf(dst, size, fmt, src[0], src[1], src[2], src[3]) >>> >= size) { >>> .... >>> .... >>> >>> Was there a specific purpose of changing the more easy and simple way >>> of %u instead of the combination of %d and and-ing with 0xff ?? >>> It essentially gives the same result but increases overhead (i think) in >>> the more >>> recent version. >>> >> I just noticed I made a mistake. The second code is libc's version of >> inet_ntoa. But the question still counts. Why not use the plain >> simpler version of libc ? >> > > I don't see ucp[] in RELENG_6, RELENG_7 or CURRENT. Where did you get > the version shown as `7.0-RC1' above? > > I got the source code from the ftp.freebsd.org and I just downloaded 7.0-RC3 to be certain. Both in 7.0-RC1 and in 7.0-RC3 in src/sys/libkern/ is the following code of inet_ntoa.c : #include __FBSDID("$FreeBSD: src/sys/libkern/inet_ntoa.c,v 1.6 2005/01/07 00:24:32 imp Exp $"); #include #include #include char * inet_ntoa(struct in_addr ina) { static char buf[4*sizeof "123"]; unsigned char *ucp = (unsigned char *)&ina; sprintf(buf, "%d.%d.%d.%d", ucp[0] & 0xff, ucp[1] & 0xff, ucp[2] & 0xff, ucp[3] & 0xff); return buf; } .....followed by the reentrant version of inet_ntoa : inet_ntoa_r On the other hand, in version 4.11 RELEASE in /usr/src/lib/libc/net/inet_ntoa.c & inet_ntop.c (actually it is inet_ntop.c code but with the same functionality) which is called by inet_ntoa there is : static const char * inet_ntop4(src, dst, size) const u_char *src; char *dst; size_t size; { static const char fmt[] = "%u.%u.%u.%u"; if ((size_t)snprintf(dst, size, fmt, src[0], src[1], src[2], src[3]) >= size) { errno = ENOSPC; return (NULL); } return (dst); }