[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCHv2] addrToString: give better error message



On 04/22/2010 02:33 PM, Matthias Bolte wrote:
>> +        char ip[INET6_ADDRSTRLEN];
>> +
>> +        if (inet_ntop(sa->sa_family,
>> +                      (sa->sa_family == AF_INET
>> +                       ? (void *)&((struct sockaddr_in *)sa)->sin_addr
>> +                       : (void *)&((struct sockaddr_in6 *)sa)->sin6_addr),
> 
> Could we avoid this void * cast? The same cast is in
> src/remote/remote_driver.c too.

Yeah, I thought it was pretty ugly; gcc is (rightfully) complaining
(which in turn failed with -Werror) that sin_addr and sin6_addr are
different types, and therefore warned that the ?: had issues without at
least one of the two casts to void*.  I pushed, after dropping ?: and
instead using:

        void *rawaddr;

        if (sa->sa_family == AF_INET)
            rawaddr = &((struct sockaddr_in *)sa)->sin_addr;
        else
            rawaddr = &((struct sockaddr_in6 *)sa)->sin6_addr;

        if (inet_ntop(sa->sa_family, rawaddr, ip, sizeof ip)) {

> ACK.

Thanks.

-- 
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]