summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/getaddrinfo.c
diff options
context:
space:
mode:
authoritojun <>2002-08-27 08:53:13 +0000
committeritojun <>2002-08-27 08:53:13 +0000
commit69e635aa5ff8682829c1dabe85f07036fe78a8d8 (patch)
tree3604890584cae1bff5aea913e0b4e8dc699ee452 /src/lib/libc/net/getaddrinfo.c
parent1da97f9d763891c390b0295da95f556484c36d8f (diff)
downloadopenbsd-69e635aa5ff8682829c1dabe85f07036fe78a8d8.tar.gz
openbsd-69e635aa5ff8682829c1dabe85f07036fe78a8d8.tar.bz2
openbsd-69e635aa5ff8682829c1dabe85f07036fe78a8d8.zip
allocate 64K recieve buffer for DNS responses.
Diffstat (limited to 'src/lib/libc/net/getaddrinfo.c')
-rw-r--r--src/lib/libc/net/getaddrinfo.c51
1 files changed, 33 insertions, 18 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
190typedef union { 186typedef 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