diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libc/net/res_send.c | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/lib/libc/net/res_send.c b/src/lib/libc/net/res_send.c index f7631350bc..187210cbd8 100644 --- a/src/lib/libc/net/res_send.c +++ b/src/lib/libc/net/res_send.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: res_send.c,v 1.19 2005/08/06 20:30:04 espie Exp $ */ | 1 | /* $OpenBSD: res_send.c,v 1.20 2008/04/18 21:36:32 djm Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * ++Copyright++ 1985, 1989, 1993 | 4 | * ++Copyright++ 1985, 1989, 1993 |
| @@ -75,10 +75,11 @@ | |||
| 75 | #include <arpa/nameser.h> | 75 | #include <arpa/nameser.h> |
| 76 | #include <arpa/inet.h> | 76 | #include <arpa/inet.h> |
| 77 | 77 | ||
| 78 | #include <stdio.h> | ||
| 79 | #include <netdb.h> | ||
| 80 | #include <errno.h> | 78 | #include <errno.h> |
| 79 | #include <netdb.h> | ||
| 80 | #include <poll.h> | ||
| 81 | #include <resolv.h> | 81 | #include <resolv.h> |
| 82 | #include <stdio.h> | ||
| 82 | #include <stdlib.h> | 83 | #include <stdlib.h> |
| 83 | #include <string.h> | 84 | #include <string.h> |
| 84 | #include <unistd.h> | 85 | #include <unistd.h> |
| @@ -466,7 +467,7 @@ res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) | |||
| 466 | /* | 467 | /* |
| 467 | * Receive length & response | 468 | * Receive length & response |
| 468 | */ | 469 | */ |
| 469 | read_len: | 470 | read_len: |
| 470 | cp = ans; | 471 | cp = ans; |
| 471 | len = INT16SZ; | 472 | len = INT16SZ; |
| 472 | while ((n = read(s, (char *)cp, (int)len)) > 0) { | 473 | while ((n = read(s, (char *)cp, (int)len)) > 0) { |
| @@ -553,8 +554,8 @@ read_len: | |||
| 553 | /* | 554 | /* |
| 554 | * Use datagrams. | 555 | * Use datagrams. |
| 555 | */ | 556 | */ |
| 556 | struct timeval timeout; | 557 | struct pollfd pfd; |
| 557 | fd_set *dsmaskp; | 558 | int timeout; |
| 558 | struct sockaddr_storage from; | 559 | struct sockaddr_storage from; |
| 559 | socklen_t fromlen; | 560 | socklen_t fromlen; |
| 560 | 561 | ||
| @@ -594,7 +595,7 @@ read_len: | |||
| 594 | * ICMP port unreachable message to be returned. | 595 | * ICMP port unreachable message to be returned. |
| 595 | * If our datagram socket is "connected" to the | 596 | * If our datagram socket is "connected" to the |
| 596 | * server, we get an ECONNREFUSED error on the next | 597 | * server, we get an ECONNREFUSED error on the next |
| 597 | * socket operation, and select returns if the | 598 | * socket operation, and poll returns if the |
| 598 | * error message is received. We can thus detect | 599 | * error message is received. We can thus detect |
| 599 | * the absence of a nameserver without timing out. | 600 | * the absence of a nameserver without timing out. |
| 600 | * If we have sent queries to at least two servers, | 601 | * If we have sent queries to at least two servers, |
| @@ -676,27 +677,19 @@ read_len: | |||
| 676 | /* | 677 | /* |
| 677 | * Wait for reply | 678 | * Wait for reply |
| 678 | */ | 679 | */ |
| 679 | timeout.tv_sec = (_resp->retrans << try); | 680 | timeout = 1000 * (_resp->retrans << try); |
| 680 | if (try > 0) | 681 | if (try > 0) |
| 681 | timeout.tv_sec /= _resp->nscount; | 682 | timeout /= _resp->nscount; |
| 682 | if ((long) timeout.tv_sec <= 0) | 683 | if (timeout < 1000) |
| 683 | timeout.tv_sec = 1; | 684 | timeout = 1000; |
| 684 | timeout.tv_usec = 0; | ||
| 685 | wait: | 685 | wait: |
| 686 | dsmaskp = (fd_set *)calloc(howmany(s+1, NFDBITS), | 686 | pfd.fd = s; |
| 687 | sizeof(fd_mask)); | 687 | pfd.events = POLLIN; |
| 688 | if (dsmaskp == NULL) { | 688 | n = poll(&pfd, 1, timeout); |
| 689 | res_close(); | ||
| 690 | goto next_ns; | ||
| 691 | } | ||
| 692 | FD_SET(s, dsmaskp); | ||
| 693 | n = select(s+1, dsmaskp, (fd_set *)NULL, | ||
| 694 | (fd_set *)NULL, &timeout); | ||
| 695 | free(dsmaskp); | ||
| 696 | if (n < 0) { | 689 | if (n < 0) { |
| 697 | if (errno == EINTR) | 690 | if (errno == EINTR) |
| 698 | goto wait; | 691 | goto wait; |
| 699 | Perror(stderr, "select", errno); | 692 | Perror(stderr, "poll", errno); |
| 700 | res_close(); | 693 | res_close(); |
| 701 | goto next_ns; | 694 | goto next_ns; |
| 702 | } | 695 | } |
