M
Mark
Hello,
In a snippet below is there a real benefit not to address 'prefix4/prefix6'
members of a union:
#define IPV4_MAX_BYTELEN 4
#define IPV6_MAX_BYTELEN 16
struct prefix
{
u_int8_t family;
u_int8_t prefixlen;
union
{
u_int8_t prefix;
struct in_addr prefix4;
struct in6_addr prefix6;
u_int8_t val[9];
} u;
};
....
unsigned char key [40];
memcpy (key, obj->u.val, IPV4_MAX_BYTELEN);
memcpy (key, obj->u.val, IPV6_MAX_BYTELEN);
rather than in a more readable way:
memcpy (key, &obj->u.prefix4, IPV4_MAX_BYTELEN);
memcpy (key, &obj->u.prefix6, IPV6_MAX_BYTELEN);
Would you suggest/speculate what was the author of this code trying to
achieve? (I just can't see an obvious explanation to this.)
Thanks in advance.
Mark
In a snippet below is there a real benefit not to address 'prefix4/prefix6'
members of a union:
#define IPV4_MAX_BYTELEN 4
#define IPV6_MAX_BYTELEN 16
struct prefix
{
u_int8_t family;
u_int8_t prefixlen;
union
{
u_int8_t prefix;
struct in_addr prefix4;
struct in6_addr prefix6;
u_int8_t val[9];
} u;
};
....
unsigned char key [40];
memcpy (key, obj->u.val, IPV4_MAX_BYTELEN);
memcpy (key, obj->u.val, IPV6_MAX_BYTELEN);
rather than in a more readable way:
memcpy (key, &obj->u.prefix4, IPV4_MAX_BYTELEN);
memcpy (key, &obj->u.prefix6, IPV6_MAX_BYTELEN);
Would you suggest/speculate what was the author of this code trying to
achieve? (I just can't see an obvious explanation to this.)
Thanks in advance.
Mark