mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
Fix cast errors with clang
Build with clang fails with: CC util/libvirt_util_la-virsocketaddr.lo util/virsocketaddr.c:904:17: error: cast from 'struct sockaddr *' to 'struct sockaddr_in *' increases required alignment from 1 to 4 [-Werror,-Wcast-align] inet4 = (struct sockaddr_in*) res->ai_addr; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ util/virsocketaddr.c:909:17: error: cast from 'struct sockaddr *' to 'struct sockaddr_in6 *' increases required alignment from 1 to 4 [-Werror,-Wcast-align] inet6 = (struct sockaddr_in6*) res->ai_addr; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2 errors generated. Fix that by replacing virSocketAddrParseInternal() call with virSocketAddrParse() in the virSocketAddrIsNumericLocalhost() function. virSocketAddrParse stores an address in virSocketAddr. virSocketAddr uses a union to store an address, so it doesn't need casting.
This commit is contained in:
parent
67be57eb85
commit
82e4f85ce0
@ -890,28 +890,19 @@ virSocketAddrNumericFamily(const char *address)
|
|||||||
bool
|
bool
|
||||||
virSocketAddrIsNumericLocalhost(const char *addr)
|
virSocketAddrIsNumericLocalhost(const char *addr)
|
||||||
{
|
{
|
||||||
struct addrinfo *res;
|
virSocketAddr res;
|
||||||
struct in_addr tmp = { .s_addr = htonl(INADDR_LOOPBACK) };
|
struct in_addr tmp = { .s_addr = htonl(INADDR_LOOPBACK) };
|
||||||
struct sockaddr_in *inet4;
|
|
||||||
struct sockaddr_in6 *inet6;
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if (virSocketAddrParseInternal(&res, addr, AF_UNSPEC, false) < 0)
|
if (virSocketAddrParse(&res, addr, AF_UNSPEC) < 0)
|
||||||
return ret;
|
return false;
|
||||||
|
|
||||||
switch (res->ai_addr->sa_family) {
|
switch (res.data.stor.ss_family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
inet4 = (struct sockaddr_in*) res->ai_addr;
|
return memcmp(&res.data.inet4.sin_addr.s_addr, &tmp.s_addr,
|
||||||
ret = memcmp(&inet4->sin_addr.s_addr, &tmp.s_addr,
|
sizeof(res.data.inet4.sin_addr.s_addr)) == 0;
|
||||||
sizeof(inet4->sin_addr.s_addr)) == 0;
|
|
||||||
break;
|
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
inet6 = (struct sockaddr_in6*) res->ai_addr;
|
return IN6_IS_ADDR_LOOPBACK(&res.data.inet6.sin6_addr);
|
||||||
ret = IN6_IS_ADDR_LOOPBACK(&(inet6->sin6_addr));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(res);
|
return false;
|
||||||
return ret;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user