Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Oct 2013 00:41:13 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Kevin Lo <kevlo@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r256505 - head/sys/netinet
Message-ID:  <20131015231355.H1194@besplex.bde.org>
In-Reply-To: <201310150735.r9F7ZdIt094705@svn.freebsd.org>
References:  <201310150735.r9F7ZdIt094705@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 15 Oct 2013, Kevin Lo wrote:

> Log:
>  Treat INADDR_NONE as uint32_t.
>
>  Reviewed by:	glebius

> Modified:
>  head/sys/netinet/in.h
>
> Modified: head/sys/netinet/in.h
> ==============================================================================
> --- head/sys/netinet/in.h	Tue Oct 15 06:38:40 2013	(r256504)
> +++ head/sys/netinet/in.h	Tue Oct 15 07:35:39 2013	(r256505)
> @@ -379,7 +379,7 @@ __END_DECLS
>
> #define	INADDR_LOOPBACK		(u_int32_t)0x7f000001

The old casts of inet address macros are remarkably buggy:
- all are missing parentheses.  This gives an incorrect parse for weird
   code like INADDR_LOOPBACK[array] (this syntax is valid but gives
   different semantics to array[INADDR_LOOPBACK], unlike if the array and
   the index are either correctly written macros or not macros.
- all cast to u_int32_t instead of to in_addr_t.  This is not just a
   style bug.  u_int32_t isn't even declared, except accidentally via
   namespace pollution.

> #ifndef _KERNEL
> -#define	INADDR_NONE		0xffffffff		/* -1 return */
> +#define	INADDR_NONE		(uint32_t)0xffffffff	/* -1 return */

This cast has no effect (except to add bugs) on any supported arch, since
all supported arches have 32-bit ints.

I first thought that this copied all the bugs from one of the old casts.
Actually, it uses a not-incorrect type, so its bugs are only:
- missing parentheses
- the type is not visually identical to the type of an inet address
   (in_addr_t)
- it is a style bug to not be bug for bug compatible with the spelling in
   the old casts.

> #endif
>
> #define	INADDR_UNSPEC_GROUP	(u_int32_t)0xe0000000	/* 224.0.0.0 */
>

u_int32_t is also used in many non-address macros starting with IN_CLASSA().
These macros don't aren't missing parentheses.

I thought that namespace errors in <net/in.h> had all been fixed.  It
carefully declares in_addr_t and uint32_t, but still uses u_int32_t in
the POSIX inet address macros; these macros are also placed before the
typedefs.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20131015231355.H1194>