[hipl-dev] Re: [Merge] lp:~hipl-core/hipl/libhip into lp:hipl

  • From: David Martin <david.martin.mailbox@xxxxxxxxxxxxxx>
  • To: mp+93782@xxxxxxxxxxxxxxxxxx
  • Date: Mon, 27 Feb 2012 09:07:18 -0000

Hi,

On Mon, Feb 27, 2012 at 9:04 AM, Stefan Götz <stefan.goetz@xxxxxx> wrote:

>> +    is_ipv4 = (src_addr.sa_family == AF_INET);
>> +    if (is_ipv4) {
>> +        saddr4 = (struct sockaddr_in *) &src_addr;
>> +        IPV4_TO_IPV6_MAP(&saddr4->sin_addr, &ctx->src_addr);
>> +        ctx->msg_ports.src_port = ntohs(saddr4->sin_port);
>> +    } else {
>> +        saddr6 = (struct sockaddr_in6 *) &src_addr;
>> +        memcpy(&ctx->dst_addr, &saddr6->sin6_addr, sizeof(struct in6_addr));
>
> a plain assignment instead of memcpy is easier to read in such cases, but 
> that is a matter of taste.

Either way there's a wrapper function for this purpose in
lib/core/prefix.c: ipv6_addr_copy(). Not sure if assignments are a
good idea but the wrapper should definitely be used instead of the
manual memcpy() with sizeof(). :)

-- 
https://code.launchpad.net/~hipl-core/hipl/libhip/+merge/93782
Your team HIPL core team is subscribed to branch lp:hipl.

Other related posts: