mirror of
https://frontier.innolan.net/rainlance/c-ares.git
synced 2025-10-06 03:09:40 +00:00
Fix GCC 4 compiler warning 'dereferencing type-punned pointer might break strict-aliasing rules'.
This commit is contained in:
@ -435,6 +435,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
|
|||||||
#ifdef HAVE_RECVFROM
|
#ifdef HAVE_RECVFROM
|
||||||
ares_socklen_t fromlen;
|
ares_socklen_t fromlen;
|
||||||
union {
|
union {
|
||||||
|
struct sockaddr sa;
|
||||||
struct sockaddr_in sa4;
|
struct sockaddr_in sa4;
|
||||||
struct sockaddr_in6 sa6;
|
struct sockaddr_in6 sa6;
|
||||||
} from;
|
} from;
|
||||||
@ -478,7 +479,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
|
|||||||
else
|
else
|
||||||
fromlen = sizeof(from.sa6);
|
fromlen = sizeof(from.sa6);
|
||||||
count = (ssize_t)recvfrom(server->udp_socket, (void *)buf, sizeof(buf),
|
count = (ssize_t)recvfrom(server->udp_socket, (void *)buf, sizeof(buf),
|
||||||
0, (struct sockaddr *)&from, &fromlen);
|
0, &from.sa, &fromlen);
|
||||||
#else
|
#else
|
||||||
count = sread(server->udp_socket, buf, sizeof(buf));
|
count = sread(server->udp_socket, buf, sizeof(buf));
|
||||||
#endif
|
#endif
|
||||||
@ -487,7 +488,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
|
|||||||
else if (count <= 0)
|
else if (count <= 0)
|
||||||
handle_error(channel, i, now);
|
handle_error(channel, i, now);
|
||||||
#ifdef HAVE_RECVFROM
|
#ifdef HAVE_RECVFROM
|
||||||
else if (!same_address((struct sockaddr *)&from, &server->addr))
|
else if (!same_address(&from.sa, &server->addr))
|
||||||
/* The address the response comes from does not match
|
/* The address the response comes from does not match
|
||||||
* the address we sent the request to. Someone may be
|
* the address we sent the request to. Someone may be
|
||||||
* attempting to perform a cache poisoning attack. */
|
* attempting to perform a cache poisoning attack. */
|
||||||
@ -870,6 +871,12 @@ static int setsocknonblock(ares_socket_t sockfd, /* operate on this */
|
|||||||
|
|
||||||
static int configure_socket(ares_socket_t s, int family, ares_channel channel)
|
static int configure_socket(ares_socket_t s, int family, ares_channel channel)
|
||||||
{
|
{
|
||||||
|
union {
|
||||||
|
struct sockaddr sa;
|
||||||
|
struct sockaddr_in sa4;
|
||||||
|
struct sockaddr_in6 sa6;
|
||||||
|
} local;
|
||||||
|
|
||||||
setsocknonblock(s, TRUE);
|
setsocknonblock(s, TRUE);
|
||||||
|
|
||||||
#if defined(FD_CLOEXEC) && !defined(MSDOS)
|
#if defined(FD_CLOEXEC) && !defined(MSDOS)
|
||||||
@ -903,21 +910,19 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
|
|||||||
|
|
||||||
if (family == AF_INET) {
|
if (family == AF_INET) {
|
||||||
if (channel->local_ip4) {
|
if (channel->local_ip4) {
|
||||||
struct sockaddr_in sa;
|
memset(&local.sa4, 0, sizeof(local.sa4));
|
||||||
memset(&sa, 0, sizeof(sa));
|
local.sa4.sin_family = AF_INET;
|
||||||
sa.sin_family = AF_INET;
|
local.sa4.sin_addr.s_addr = htonl(channel->local_ip4);
|
||||||
sa.sin_addr.s_addr = htonl(channel->local_ip4);
|
if (bind(s, &local.sa, sizeof(local.sa4)) < 0)
|
||||||
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (family == AF_INET6) {
|
else if (family == AF_INET6) {
|
||||||
if (memcmp(channel->local_ip6, &ares_in6addr_any, sizeof(channel->local_ip6)) != 0) {
|
if (memcmp(channel->local_ip6, &ares_in6addr_any, sizeof(channel->local_ip6)) != 0) {
|
||||||
struct sockaddr_in6 sa;
|
memset(&local.sa6, 0, sizeof(local.sa6));
|
||||||
memset(&sa, 0, sizeof(sa));
|
local.sa6.sin6_family = AF_INET6;
|
||||||
sa.sin6_family = AF_INET6;
|
memcpy(&local.sa6.sin6_addr, channel->local_ip6, sizeof(channel->local_ip6));
|
||||||
memcpy(&sa.sin6_addr, channel->local_ip6, sizeof(channel->local_ip6));
|
if (bind(s, &local.sa, sizeof(local.sa6)) < 0)
|
||||||
if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user