[Olsr-dev] [PATCH v1 1/2] android: fix type punning warnings on IN6_IS_ADDR_V4MAPPED
Hans-Christoph Steiner
(spam-protected)
Tue Oct 23 17:10:23 CEST 2012
If that works, it is OK by me. My inclination would still be to change the
definition of v6 in a #ifdef __ANDROID__ and make it match the Android
definition. Just seems cleaner to me.
.hc
On 10/23/2012 10:11 AM, Ferry Huberts wrote:
> How about this then:
>
>> diff --git a/src/ipcalc.h b/src/ipcalc.h
>> index 30b8068..f6836d4 100644
>> --- a/src/ipcalc.h
>> +++ b/src/ipcalc.h
>> @@ -161,9 +161,19 @@ sockaddr4_to_string(struct ipaddr_str *const buf, const
>> struct sockaddr *const a
>> return ip4_to_string(buf, addr4->sin_addr);
>> }
>>
>> +
>> 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)
>> +#ifdef __ANDROID__
>> + #define IN6_IS_ADDR_V4MAPPED_ANDROID_WORKAROUND(a) \
>> + ((((__const uint32_t *) (a))[0] == 0) \
>> + && (((__const uint32_t *) (a))[1] == 0) \
>> + && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
>> + bool v4mapped = IN6_IS_ADDR_V4MAPPED_ANDROID_WORKAROUND(&p->prefix.v6);
>> +#else
>> + bool v4mapped = IN6_IS_ADDR_V4MAPPED(&p->prefix.v6);
>> +#endif
>> + return olsr_cnf->ip_version == AF_INET6 && v4mapped
>> && p->prefix_len >= ipv6_mappedv4_route.prefix_len;
>> }
>
>
>
>
>
> On 22-10-12 20:01, Hans-Christoph Steiner wrote:
>>
>>
>> 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