IPv6 address copy optimization in C

c, glibc, ipv6, linux, memcpy

Solution

You should just do `IP2 = IP1;`, and let the compiler deal with it.

Problem

since `memcpy` should be highly optimized nowadays, does it still make sense to optimize the copy of Ipv6 addresses using explicit loop unrolling ? ``` #include <netinet/in.h> struct in6_addr IP_1; struct in6_addr IP_2; ; ; IP2.__in6_u.__u6_addr32[0] = IP1.__in6_u.__u6_addr32[0]; IP2.__in6_u.__u6_addr32[1] = IP1.__in6_u.__u6_addr32[1]; IP2.__in6_u.__u6_addr32[2] = IP1.__in6_u.__u6_addr32[2]; IP2.__in6_u.__u6_addr32[3] = IP1.__in6_u.__u6_addr32[3]; ``` Note that the code above is best suited for 32-bit architectures. Is there a best practice I do not know ?

Original source