diff options
author | Yang Tse <yangsita@gmail.com> | 2008-08-26 03:08:27 +0000 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2008-08-26 03:08:27 +0000 |
commit | c035f2d3a4d847328342d46b791da5d314a83bfa (patch) | |
tree | 87f5d3122df1481359667d49036e86d70a9e4565 /ares_process.c | |
parent | 2b838e85e7da467b37a092473caa14014fc0717b (diff) | |
download | c-ares-c035f2d3a4d847328342d46b791da5d314a83bfa.tar.gz c-ares-c035f2d3a4d847328342d46b791da5d314a83bfa.tar.bz2 c-ares-c035f2d3a4d847328342d46b791da5d314a83bfa.zip |
Functionality only possible if recvfrom() is available.
Diffstat (limited to 'ares_process.c')
-rw-r--r-- | ares_process.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/ares_process.c b/ares_process.c index 0a99a1b..824640e 100644 --- a/ares_process.c +++ b/ares_process.c @@ -429,8 +429,10 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds, int i; ssize_t count; unsigned char buf[PACKETSZ + 1]; +#ifdef HAVE_RECVFROM struct sockaddr_in from; socklen_t fromlen; +#endif if(!read_fds && (read_fd == ARES_SOCKET_BAD)) /* no possible action */ @@ -464,23 +466,24 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds, /* To reduce event loop overhead, read and process as many * packets as we can. */ do { - /* Must memset 'from' to 0 as recvfrom() on some systems may - * not use 'from' at all if it doesn't support receiving the - * source address of the response */ - memset(&from, 0, sizeof(from)); +#ifdef HAVE_RECVFROM fromlen = sizeof(from); count = (ssize_t)recvfrom(server->udp_socket, (void *)buf, sizeof(buf), 0, (struct sockaddr *)&from, &fromlen); +#else + count = sread(server->udp_socket, buf, sizeof(buf)); +#endif if (count == -1 && try_again(SOCKERRNO)) continue; else if (count <= 0) handle_error(channel, i, now); - else if (fromlen && from.sin_addr.s_addr != 0 && - from.sin_addr.s_addr != server->addr.s_addr) +#ifdef HAVE_RECVFROM + else if (from.sin_addr.s_addr != server->addr.s_addr) /* Address response came from did not match the address * we sent the request to. Someone may be attempting * to perform a cache poisoning attack */ break; +#endif else process_answer(channel, buf, (int)count, i, 0, now); } while (count > 0); |