[libvirt] [PATCH 1/4] util: introduce a new helper for get interface IPv6 address
lhuang
lhuang at redhat.com
Wed Feb 25 09:52:32 UTC 2015
On 02/25/2015 01:42 AM, John Ferlan wrote:
>
> 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...
>
Thanks your review and help and i have changed some place for this part,
please see the email i replied before(just now).
>> 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;
>> }
>>
Luyao
More information about the libvir-list
mailing list