[Olsr-dev] [PATCH v1 1/2] android: fix type punning warnings on IN6_IS_ADDR_V4MAPPED

Hans-Christoph Steiner (spam-protected)
Mon Oct 22 20:01:40 CEST 2012



On 10/22/2012 01:44 PM, Henning Rogge wrote:
> On Mon, Oct 22, 2012 at 7:37 PM, Hans-Christoph Steiner
> <(spam-protected)> wrote:
>> On 10/22/2012 12:50 PM, Henning Rogge wrote:
>>> I must admit I still have trouble why the compiler has trouble with
>>> the old statement. The new one is a crazy thing, some special GCC
>>> extension.
>>>
>>> If we replace it, I would suggest building an inline function that
>>> takes the "olsr_ip_addr" union and gives back a boolean. Much better
>>> than trying to fix a crazy preprocessor command.
>>
>> Did you look at the Android header snippet I posted in this thread?  Once you
>> do, its clear why the compiler is throwing that warning.  The Android header
>> declares things differently and the GNU header.  The current olsrd code
>> follows the GNU definition.
> 
> What would you two think about this patch? That sidesteps the whole
> problem quite easily.
> 
> diff --git a/src/ipcalc.h b/src/ipcalc.h
> index 30b8068..aeb77b7 100644
> --- a/src/ipcalc.h
> +++ b/src/ipcalc.h
> @@ -163,7 +163,8 @@ sockaddr4_to_string(struct ipaddr_str *const buf,
> const struct sockaddr *const a
> 
>  static INLINE bool
>  is_prefix_niit_ipv6(const struct olsr_ip_prefix *p) {
> -  return olsr_cnf->ip_version == AF_INET6 &&
> IN6_IS_ADDR_V4MAPPED(&p->prefix.v6)
> +  return olsr_cnf->ip_version == AF_INET6
> +      && memcmp(p, &ipv6_mappedv4_route.prefix,
> ipv6_mappedv4_route.prefix_len/8) == 0
>        && p->prefix_len >= ipv6_mappedv4_route.prefix_len;
>  }

If that is only to avoid using an #ifdef __ANDROID__, then I think its harder
to read since its removing the clearly named IN6_IS_ADDR_V4MAPPED and
replacing it with some mem tricks.  At the very least it should be well commented.

.hc




More information about the Olsr-dev mailing list