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 | |
| 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/getaddrinfo.c | 51 | ||||
| -rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 38 | ||||
| -rw-r--r-- | src/lib/libc/net/getnetnamadr.c | 37 |
3 files changed, 78 insertions, 48 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index db15e62668..915286a404 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getaddrinfo.c,v 1.42 2002/08/22 16:35:37 itojun Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.43 2002/08/27 08:53:13 itojun Exp $ */ |
| 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
| 3 | 3 | ||
| 4 | /* | 4 | /* |
| @@ -181,11 +181,7 @@ static const struct explore explore[] = { | |||
| 181 | #define PTON_MAX 4 | 181 | #define PTON_MAX 4 |
| 182 | #endif | 182 | #endif |
| 183 | 183 | ||
| 184 | #if PACKETSZ > 1024 | 184 | #define MAXPACKET (64*1024) |
| 185 | #define MAXPACKET PACKETSZ | ||
| 186 | #else | ||
| 187 | #define MAXPACKET 1024 | ||
| 188 | #endif | ||
| 189 | 185 | ||
| 190 | typedef union { | 186 | typedef union { |
| 191 | HEADER hdr; | 187 | HEADER hdr; |
| @@ -1230,7 +1226,7 @@ _dns_getaddrinfo(name, pai) | |||
| 1230 | const struct addrinfo *pai; | 1226 | const struct addrinfo *pai; |
| 1231 | { | 1227 | { |
| 1232 | struct addrinfo *ai; | 1228 | struct addrinfo *ai; |
| 1233 | querybuf buf, buf2; | 1229 | querybuf *buf, *buf2; |
| 1234 | struct addrinfo sentinel, *cur; | 1230 | struct addrinfo sentinel, *cur; |
| 1235 | struct res_target q, q2; | 1231 | struct res_target q, q2; |
| 1236 | 1232 | ||
| @@ -1239,47 +1235,66 @@ _dns_getaddrinfo(name, pai) | |||
| 1239 | memset(&sentinel, 0, sizeof(sentinel)); | 1235 | memset(&sentinel, 0, sizeof(sentinel)); |
| 1240 | cur = &sentinel; | 1236 | cur = &sentinel; |
| 1241 | 1237 | ||
| 1238 | buf = malloc(sizeof(*buf)); | ||
| 1239 | if (buf == NULL) { | ||
| 1240 | h_errno = NETDB_INTERNAL; | ||
| 1241 | return NULL; | ||
| 1242 | } | ||
| 1243 | buf2 = malloc(sizeof(*buf2)); | ||
| 1244 | if (buf2 == NULL) { | ||
| 1245 | free(buf); | ||
| 1246 | h_errno = NETDB_INTERNAL; | ||
| 1247 | return NULL; | ||
| 1248 | } | ||
| 1249 | |||
| 1242 | switch (pai->ai_family) { | 1250 | switch (pai->ai_family) { |
| 1243 | case AF_UNSPEC: | 1251 | case AF_UNSPEC: |
| 1244 | /* prefer IPv6 */ | 1252 | /* prefer IPv6 */ |
| 1245 | q.qclass = C_IN; | 1253 | q.qclass = C_IN; |
| 1246 | q.qtype = T_AAAA; | 1254 | q.qtype = T_AAAA; |
| 1247 | q.answer = buf.buf; | 1255 | q.answer = buf->buf; |
| 1248 | q.anslen = sizeof(buf); | 1256 | q.anslen = sizeof(buf->buf); |
| 1249 | q.next = &q2; | 1257 | q.next = &q2; |
| 1250 | q2.qclass = C_IN; | 1258 | q2.qclass = C_IN; |
| 1251 | q2.qtype = T_A; | 1259 | q2.qtype = T_A; |
| 1252 | q2.answer = buf2.buf; | 1260 | q2.answer = buf2->buf; |
| 1253 | q2.anslen = sizeof(buf2); | 1261 | q2.anslen = sizeof(buf2->buf); |
| 1254 | break; | 1262 | break; |
| 1255 | case AF_INET: | 1263 | case AF_INET: |
| 1256 | q.qclass = C_IN; | 1264 | q.qclass = C_IN; |
| 1257 | q.qtype = T_A; | 1265 | q.qtype = T_A; |
| 1258 | q.answer = buf.buf; | 1266 | q.answer = buf->buf; |
| 1259 | q.anslen = sizeof(buf); | 1267 | q.anslen = sizeof(buf->buf); |
| 1260 | break; | 1268 | break; |
| 1261 | case AF_INET6: | 1269 | case AF_INET6: |
| 1262 | q.qclass = C_IN; | 1270 | q.qclass = C_IN; |
| 1263 | q.qtype = T_AAAA; | 1271 | q.qtype = T_AAAA; |
| 1264 | q.answer = buf.buf; | 1272 | q.answer = buf->buf; |
| 1265 | q.anslen = sizeof(buf); | 1273 | q.anslen = sizeof(buf->buf); |
| 1266 | break; | 1274 | break; |
| 1267 | default: | 1275 | default: |
| 1276 | free(buf); | ||
| 1277 | free(buf2); | ||
| 1268 | return NULL; | 1278 | return NULL; |
| 1269 | } | 1279 | } |
| 1270 | if (res_searchN(name, &q) < 0) | 1280 | if (res_searchN(name, &q) < 0) { |
| 1281 | free(buf); | ||
| 1282 | free(buf2); | ||
| 1271 | return NULL; | 1283 | return NULL; |
| 1272 | ai = getanswer(&buf, q.n, q.name, q.qtype, pai); | 1284 | } |
| 1285 | ai = getanswer(buf, q.n, q.name, q.qtype, pai); | ||
| 1273 | if (ai) { | 1286 | if (ai) { |
| 1274 | cur->ai_next = ai; | 1287 | cur->ai_next = ai; |
| 1275 | while (cur && cur->ai_next) | 1288 | while (cur && cur->ai_next) |
| 1276 | cur = cur->ai_next; | 1289 | cur = cur->ai_next; |
| 1277 | } | 1290 | } |
| 1278 | if (q.next) { | 1291 | if (q.next) { |
| 1279 | ai = getanswer(&buf2, q2.n, q2.name, q2.qtype, pai); | 1292 | ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai); |
| 1280 | if (ai) | 1293 | if (ai) |
| 1281 | cur->ai_next = ai; | 1294 | cur->ai_next = ai; |
| 1282 | } | 1295 | } |
| 1296 | free(buf); | ||
| 1297 | free(buf2); | ||
| 1283 | return sentinel.ai_next; | 1298 | return sentinel.ai_next; |
| 1284 | } | 1299 | } |
| 1285 | 1300 | ||
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); |
diff --git a/src/lib/libc/net/getnetnamadr.c b/src/lib/libc/net/getnetnamadr.c index 44810337bd..abbfdbd64c 100644 --- a/src/lib/libc/net/getnetnamadr.c +++ b/src/lib/libc/net/getnetnamadr.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getnetnamadr.c,v 1.17 2002/07/25 21:13:45 deraadt Exp $ */ | 1 | /* $OpenBSD: getnetnamadr.c,v 1.18 2002/08/27 08:53:13 itojun Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1997, Jason Downs. All rights reserved. | 4 | * Copyright (c) 1997, Jason Downs. All rights reserved. |
| @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; | |||
| 77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; | 77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; |
| 78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; | 78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; |
| 79 | #else | 79 | #else |
| 80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.17 2002/07/25 21:13:45 deraadt Exp $"; | 80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.18 2002/08/27 08:53:13 itojun Exp $"; |
| 81 | #endif | 81 | #endif |
| 82 | #endif /* LIBC_SCCS and not lint */ | 82 | #endif /* LIBC_SCCS and not lint */ |
| 83 | 83 | ||
| @@ -94,6 +94,7 @@ static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.17 2002/07/25 21:13:45 deraa | |||
| 94 | #include <ctype.h> | 94 | #include <ctype.h> |
| 95 | #include <errno.h> | 95 | #include <errno.h> |
| 96 | #include <string.h> | 96 | #include <string.h> |
| 97 | #include <stdlib.h> | ||
| 97 | 98 | ||
| 98 | extern int h_errno; | 99 | extern int h_errno; |
| 99 | 100 | ||
| @@ -106,11 +107,7 @@ int _hokchar(const char *); | |||
| 106 | #define BYNAME 1 | 107 | #define BYNAME 1 |
| 107 | #define MAXALIASES 35 | 108 | #define MAXALIASES 35 |
| 108 | 109 | ||
| 109 | #if PACKETSZ > 1024 | 110 | #define MAXPACKET (64*1024) |
| 110 | #define MAXPACKET PACKETSZ | ||
| 111 | #else | ||
| 112 | #define MAXPACKET 1024 | ||
| 113 | #endif | ||
| 114 | 111 | ||
| 115 | typedef union { | 112 | typedef union { |
| 116 | HEADER hdr; | 113 | HEADER hdr; |
| @@ -252,7 +249,7 @@ getnetbyaddr(net, net_type) | |||
| 252 | { | 249 | { |
| 253 | unsigned int netbr[4]; | 250 | unsigned int netbr[4]; |
| 254 | int nn, anslen; | 251 | int nn, anslen; |
| 255 | querybuf buf; | 252 | querybuf *buf; |
| 256 | char qbuf[MAXDNAME]; | 253 | char qbuf[MAXDNAME]; |
| 257 | in_addr_t net2; | 254 | in_addr_t net2; |
| 258 | struct netent *net_entry = NULL; | 255 | struct netent *net_entry = NULL; |
| @@ -300,16 +297,21 @@ getnetbyaddr(net, net_type) | |||
| 300 | netbr[3], netbr[2], netbr[1], netbr[0]); | 297 | netbr[3], netbr[2], netbr[1], netbr[0]); |
| 301 | break; | 298 | break; |
| 302 | } | 299 | } |
| 303 | anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, | 300 | buf = malloc(sizeof(*buf)); |
| 304 | sizeof(buf)); | 301 | if (buf == NULL) |
| 302 | break; | ||
| 303 | anslen = res_query(qbuf, C_IN, T_PTR, buf->buf, | ||
| 304 | sizeof(buf->buf)); | ||
| 305 | if (anslen < 0) { | 305 | if (anslen < 0) { |
| 306 | free(buf); | ||
| 306 | #ifdef DEBUG | 307 | #ifdef DEBUG |
| 307 | if (_res.options & RES_DEBUG) | 308 | if (_res.options & RES_DEBUG) |
| 308 | printf("res_query failed\n"); | 309 | printf("res_query failed\n"); |
| 309 | #endif | 310 | #endif |
| 310 | break; | 311 | break; |
| 311 | } | 312 | } |
| 312 | net_entry = getnetanswer(&buf, anslen, BYADDR); | 313 | net_entry = getnetanswer(buf, anslen, BYADDR); |
| 314 | free(buf); | ||
| 313 | if (net_entry != NULL) { | 315 | if (net_entry != NULL) { |
| 314 | unsigned u_net = net; /* maybe net should be unsigned ? */ | 316 | unsigned u_net = net; /* maybe net should be unsigned ? */ |
| 315 | 317 | ||
| @@ -336,7 +338,7 @@ getnetbyname(net) | |||
| 336 | register const char *net; | 338 | register const char *net; |
| 337 | { | 339 | { |
| 338 | int anslen; | 340 | int anslen; |
| 339 | querybuf buf; | 341 | querybuf *buf; |
| 340 | char qbuf[MAXDNAME]; | 342 | char qbuf[MAXDNAME]; |
| 341 | struct netent *net_entry = NULL; | 343 | struct netent *net_entry = NULL; |
| 342 | char lookups[MAXDNSLUS]; | 344 | char lookups[MAXDNSLUS]; |
| @@ -358,16 +360,21 @@ getnetbyname(net) | |||
| 358 | #endif /* YP */ | 360 | #endif /* YP */ |
| 359 | case 'b': | 361 | case 'b': |
| 360 | strlcpy(qbuf, net, sizeof qbuf); | 362 | strlcpy(qbuf, net, sizeof qbuf); |
| 361 | anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, | 363 | buf = malloc(sizeof(*buf)); |
| 362 | sizeof(buf)); | 364 | if (buf == NULL) |
| 365 | break; | ||
| 366 | anslen = res_search(qbuf, C_IN, T_PTR, buf->buf, | ||
| 367 | sizeof(buf->buf)); | ||
| 363 | if (anslen < 0) { | 368 | if (anslen < 0) { |
| 369 | free(buf); | ||
| 364 | #ifdef DEBUG | 370 | #ifdef DEBUG |
| 365 | if (_res.options & RES_DEBUG) | 371 | if (_res.options & RES_DEBUG) |
| 366 | printf("res_query failed\n"); | 372 | printf("res_query failed\n"); |
| 367 | #endif | 373 | #endif |
| 368 | break; | 374 | break; |
| 369 | } | 375 | } |
| 370 | net_entry = getnetanswer(&buf, anslen, BYNAME); | 376 | net_entry = getnetanswer(buf, anslen, BYNAME); |
| 377 | free(buf); | ||
| 371 | if (net_entry != NULL) | 378 | if (net_entry != NULL) |
| 372 | return (net_entry); | 379 | return (net_entry); |
| 373 | break; | 380 | break; |
