diff options
| author | itojun <> | 2002-08-27 08:53:13 +0000 |
|---|---|---|
| committer | itojun <> | 2002-08-27 08:53:13 +0000 |
| commit | 69e635aa5ff8682829c1dabe85f07036fe78a8d8 (patch) | |
| tree | 3604890584cae1bff5aea913e0b4e8dc699ee452 /src/lib/libc/net/gethostnamadr.c | |
| parent | 1da97f9d763891c390b0295da95f556484c36d8f (diff) | |
| download | openbsd-69e635aa5ff8682829c1dabe85f07036fe78a8d8.tar.gz openbsd-69e635aa5ff8682829c1dabe85f07036fe78a8d8.tar.bz2 openbsd-69e635aa5ff8682829c1dabe85f07036fe78a8d8.zip | |
allocate 64K recieve buffer for DNS responses.
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index 3ac5049e72..909ce573b7 100644 --- a/src/lib/libc/net/gethostnamadr.c +++ b/src/lib/libc/net/gethostnamadr.c | |||
| @@ -52,7 +52,7 @@ | |||
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | #if defined(LIBC_SCCS) && !defined(lint) | 54 | #if defined(LIBC_SCCS) && !defined(lint) |
| 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.52 2002/08/22 16:35:37 itojun Exp $"; | 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.53 2002/08/27 08:53:13 itojun Exp $"; |
| 56 | #endif /* LIBC_SCCS and not lint */ | 56 | #endif /* LIBC_SCCS and not lint */ |
| 57 | 57 | ||
| 58 | #include <sys/param.h> | 58 | #include <sys/param.h> |
| @@ -110,11 +110,7 @@ int _hokchar(const char *); | |||
| 110 | static const char AskedForGot[] = | 110 | static const char AskedForGot[] = |
| 111 | "gethostby*.getanswer: asked for \"%s\", got \"%s\""; | 111 | "gethostby*.getanswer: asked for \"%s\", got \"%s\""; |
| 112 | 112 | ||
| 113 | #if PACKETSZ > 1024 | 113 | #define MAXPACKET (64*1024) |
| 114 | #define MAXPACKET PACKETSZ | ||
| 115 | #else | ||
| 116 | #define MAXPACKET 1024 | ||
| 117 | #endif | ||
| 118 | 114 | ||
| 119 | typedef union { | 115 | typedef union { |
| 120 | HEADER hdr; | 116 | HEADER hdr; |
| @@ -517,7 +513,7 @@ gethostbyname2(name, af) | |||
| 517 | const char *name; | 513 | const char *name; |
| 518 | int af; | 514 | int af; |
| 519 | { | 515 | { |
| 520 | querybuf buf; | 516 | querybuf *buf; |
| 521 | register const char *cp; | 517 | register const char *cp; |
| 522 | char *bp, *ep; | 518 | char *bp, *ep; |
| 523 | int n, size, type, i; | 519 | int n, size, type, i; |
| @@ -635,15 +631,20 @@ gethostbyname2(name, af) | |||
| 635 | break; | 631 | break; |
| 636 | #endif | 632 | #endif |
| 637 | case 'b': | 633 | case 'b': |
| 638 | if ((n = res_search(name, C_IN, type, buf.buf, | 634 | buf = malloc(sizeof(*buf)); |
| 639 | sizeof(buf))) < 0) { | 635 | if (buf == NULL) |
| 636 | break; | ||
| 637 | if ((n = res_search(name, C_IN, type, buf->buf, | ||
| 638 | sizeof(buf->buf))) < 0) { | ||
| 639 | free(buf); | ||
| 640 | #ifdef DEBUG | 640 | #ifdef DEBUG |
| 641 | if (_res.options & RES_DEBUG) | 641 | if (_res.options & RES_DEBUG) |
| 642 | printf("res_search failed\n"); | 642 | printf("res_search failed\n"); |
| 643 | #endif | 643 | #endif |
| 644 | break; | 644 | break; |
| 645 | } | 645 | } |
| 646 | hp = getanswer(&buf, n, name, type); | 646 | hp = getanswer(buf, n, name, type); |
| 647 | free(buf); | ||
| 647 | break; | 648 | break; |
| 648 | case 'f': | 649 | case 'f': |
| 649 | hp = _gethtbyname2(name, af); | 650 | hp = _gethtbyname2(name, af); |
| @@ -661,7 +662,7 @@ gethostbyaddr(addr, len, af) | |||
| 661 | { | 662 | { |
| 662 | const u_char *uaddr = (const u_char *)addr; | 663 | const u_char *uaddr = (const u_char *)addr; |
| 663 | int n, size, i; | 664 | int n, size, i; |
| 664 | querybuf buf; | 665 | querybuf *buf; |
| 665 | register struct hostent *hp; | 666 | register struct hostent *hp; |
| 666 | char qbuf[MAXDNAME+1], *qp; | 667 | char qbuf[MAXDNAME+1], *qp; |
| 667 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); | 668 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); |
| @@ -741,22 +742,29 @@ gethostbyaddr(addr, len, af) | |||
| 741 | case 'b': | 742 | case 'b': |
| 742 | if (af == AF_INET6) | 743 | if (af == AF_INET6) |
| 743 | strcpy(qp, "ip6.arpa"); | 744 | strcpy(qp, "ip6.arpa"); |
| 744 | n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, | 745 | buf = malloc(sizeof(*buf)); |
| 745 | sizeof buf.buf); | 746 | if (!buf) |
| 747 | break; | ||
| 748 | n = res_query(qbuf, C_IN, T_PTR, buf->buf, | ||
| 749 | sizeof(buf->buf)); | ||
| 746 | if (n < 0 && af == AF_INET6) { | 750 | if (n < 0 && af == AF_INET6) { |
| 747 | strcpy(qp, "ip6.int"); | 751 | strcpy(qp, "ip6.int"); |
| 748 | n = res_query(qbuf, C_IN, T_PTR, | 752 | n = res_query(qbuf, C_IN, T_PTR, |
| 749 | (u_char *)buf.buf, sizeof buf.buf); | 753 | buf->buf, sizeof(buf->buf)); |
| 750 | } | 754 | } |
| 751 | if (n < 0) { | 755 | if (n < 0) { |
| 756 | free(buf); | ||
| 752 | #ifdef DEBUG | 757 | #ifdef DEBUG |
| 753 | if (_res.options & RES_DEBUG) | 758 | if (_res.options & RES_DEBUG) |
| 754 | printf("res_query failed\n"); | 759 | printf("res_query failed\n"); |
| 755 | #endif | 760 | #endif |
| 756 | break; | 761 | break; |
| 757 | } | 762 | } |
| 758 | if (!(hp = getanswer(&buf, n, qbuf, T_PTR))) | 763 | if (!(hp = getanswer(buf, n, qbuf, T_PTR))) { |
| 764 | free(buf); | ||
| 759 | break; | 765 | break; |
| 766 | } | ||
| 767 | free(buf); | ||
| 760 | hp->h_addrtype = af; | 768 | hp->h_addrtype = af; |
| 761 | hp->h_length = len; | 769 | hp->h_length = len; |
| 762 | bcopy(addr, host_addr, len); | 770 | bcopy(addr, host_addr, len); |
