On 02/24/2015 11:12 AM, John Ferlan wrote:
<...snip...>
As I'm reading the next patch I'm thinking I forgot something in the
previous one...
The "default" has been IPv4 and would seem to be the "right" thing to
return once we find an address; however, if we wanted an IPv6 address
and returned an IPv4 one, that wouldn't be good...
Leaving the following - including the capability to get either IPv6
or
IPv4 address depending upon what's desired/required:
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr ||
STRNEQ(ifa->ifa_name, ifname))
continue;
found_one = true;
if (want_ipv6 && ifa->ifa_addr->sa_family != AF_INET6)
continue;
/* Found an address to return */
addr->data.stor.ss_family = ifa->ifa_addr->sa_family;
if (ifa->ifa_addr->sa_family == AF_INET6)
addr->len = sizeof(addr->data.inet6);
memcpy(&addr->data.inet6, ifa->ifa_addr, addr->len);
} else {
} else if (!want_ipv6 && ifa->ifa_addr->sa_family == AF_INET) {
addr->len = sizeof(addr->data.inet4);
memcpy(&addr->data.inet4, ifa->ifa_addr, addr->len);
}
ret = 0;
goto cleanup;
}