socklen_t (Re: Multicast problems [PATCH])

Daniel Eischen deischen at freebsd.org
Wed Jun 20 12:34:50 UTC 2007


On Wed, 20 Jun 2007, Stefan Farfeleder wrote:

> On Tue, Jun 19, 2007 at 06:36:39PM -0400, Daniel Eischen wrote:
>
>>  POSIX states that:
>>
>>    o The <sys/socket.h> header shall define the type socklen_t,
>>      which is an integer type of width of at least 32 bits; see
>>      APPLICATION USAGE.
>>
>>  and goes on to state:
>>
>>    o The <sys/socket.h> header shall define the unsigned integer
>>      type sa_family_t.
>>
>>  This seems to imply that our socklen_t should not be an unsigned
>>  integer (uint32_t), but a signed integer.  In APPLICATION USAGE,
>>  POSIX states:
>
> I don't understand how you come to that conclusion.  Why does not
> mentioning whether socklen_t is signed or unsigned imply it should be
> signed?

Because it explicitly says unsigned for sa_family_t and does not
say unsigned for socklen_t.  To me, "integer" means a C (signed)
integer.  The fact that older APIs and implementations used "int"
might support the argument to use int32_t just for compatibility
reasons.  As it stands now, portable code has to have some sort
of autoconfig to determine whether or not to use socklen_t or int.
I don't see how you can do this with #ifdefs unless you know
OS version numbers and when socklen_t first got introduced.

>>    To forestall portability problems, it is recommended that
>>    applications not use values larger than 23^1 -1 for the
>>    socklen_t type.
>
> That just means that those values will wrap to negative values if
> socklen_t is a signed integer type.

-- 
DE


More information about the freebsd-current mailing list