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

Eric Blake eblake at redhat.com
Thu Apr 22 20:52:35 UTC 2010


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 at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100422/7d0a704c/attachment-0001.sig>


More information about the libvir-list mailing list