Giorgos Keramidas wrote:
On 2008-02-23 02:37, ithilgore <[EMAIL PROTECTED]> 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 <sys/cdefs.h>
__FBSDID("$FreeBSD: src/sys/libkern/inet_ntoa.c,v 1.6 2005/01/07
00:24:32 imp Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <netinet/in.h>
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);
}
_______________________________________________
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "[EMAIL PROTECTED]"