Re: bug in addrlist_match (with IPv6 addresses)

Matthias Andree <[email protected]> Thu, 07 Aug 2003 10:39:34 +0200
Newsgroups gmane.network.xinetd
Message-ID <[email protected]>
Steve G <[email protected]> writes:

>>>Probably the most portable way to do it is to make a
> macro
>>>
>>> #define IPV4_ADDR_OFFSET (a) ((__const uint32_t *)
> (a))[3]
>>
>>One-word interjection: Ugh.
>
> Right. :)
>
>> -  uint32_t *tmp_addr = (unsigned *)&addr->sa_data[3];
>> +  uint32_t *tmp_addr =
>> &SAIN6(addr)->sin6_addr.s6_addr32[3];
>
> I think I see what the problem is...missing parenthesis. It
> should have been: 
>
> uint32_t *tmp_addr = ((unsigned *)&addr->sa_data)[3];

Neither. You don't assign (((unsigned *)X)[N]) to uint32_t because you
don't know if sizeof unsigned == sizeof uint32_t. There's a reason why
these exist.

Besides, I'd personally add another pair of parentheses around the
IPV4_ADDR_OFFSET expansion so you don't leave a dangling [3] in the air
-- aside from disliking macros because they defeat type checking and
cause non-obvious errors to show up at strange places.

-- 
Matthias Andree