Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 May 2006 15:09:50 -0400
From:      Charles Swiger <cswiger@mac.com>
To:        Emil Kondayan <emil@ekon-bg.com>
Cc:        freebsd-net@freebsd.org
Subject:   Re: Question about netinet/ip.h
Message-ID:  <6AE303E5-13FD-4328-BDF4-25BACF429806@mac.com>
In-Reply-To: <200605312157.04027.emil@ekon-bg.com>
References:  <200605291103.k4TB38uo097477@freefall.freebsd.org> <200605312157.04027.emil@ekon-bg.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Jun 1, 2006, at 12:57 AM, Emil Kondayan wrote:
> Can someone tell me why "ip_hl" and "ip_v" are of type "u_int" when  
> the
> structure is packed and they only fill a byte?

Well, that struct definition is relying on the compiler to squeeze  
the bitfields into the smallest space required.  Some platforms  
define ip_hl and ip_v as a char called ip_vhl instead:

/*
  * Structure of an internet header, naked of options.
  */
struct ip {
#ifdef _IP_VHL
         u_char  ip_vhl;                 /* version << 4 | header  
length >> 2 */
#else
[ ...bitfields vary based on BYTE_ORDER... ]

> And my second question:do these "#define ..." directives allocate  
> space in the
> structure?

No.  They define bitmasks to access each flag bit.

-- 
-Chuck




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6AE303E5-13FD-4328-BDF4-25BACF429806>