diff options
Diffstat (limited to 'src/lib/libc/net/getaddrinfo.c')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index 0f3b6319f4..87125c89cc 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.67 2007/05/20 03:54:52 ray Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.68 2009/06/04 18:06:35 pyr 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 | /* |
@@ -233,7 +233,8 @@ static struct addrinfo *getanswer(const querybuf *, int, const char *, int, | |||
233 | static int res_queryN(const char *, struct res_target *); | 233 | static int res_queryN(const char *, struct res_target *); |
234 | static int res_searchN(const char *, struct res_target *); | 234 | static int res_searchN(const char *, struct res_target *); |
235 | static int res_querydomainN(const char *, const char *, struct res_target *); | 235 | static int res_querydomainN(const char *, const char *, struct res_target *); |
236 | static struct addrinfo *_dns_getaddrinfo(const char *, const struct addrinfo *); | 236 | static struct addrinfo *_dns_getaddrinfo(const char *, const struct addrinfo *, |
237 | const struct __res_state *); | ||
237 | 238 | ||
238 | 239 | ||
239 | /* XXX macros that make external reference is BAD. */ | 240 | /* XXX macros that make external reference is BAD. */ |
@@ -517,7 +518,7 @@ explore_fqdn(const struct addrinfo *pai, const char *hostname, | |||
517 | break; | 518 | break; |
518 | #endif | 519 | #endif |
519 | case 'b': | 520 | case 'b': |
520 | result = _dns_getaddrinfo(hostname, pai); | 521 | result = _dns_getaddrinfo(hostname, pai, _resp); |
521 | break; | 522 | break; |
522 | case 'f': | 523 | case 'f': |
523 | result = _files_getaddrinfo(hostname, pai); | 524 | result = _files_getaddrinfo(hostname, pai); |
@@ -1142,7 +1143,8 @@ getanswer(const querybuf *answer, int anslen, const char *qname, int qtype, | |||
1142 | 1143 | ||
1143 | /*ARGSUSED*/ | 1144 | /*ARGSUSED*/ |
1144 | static struct addrinfo * | 1145 | static struct addrinfo * |
1145 | _dns_getaddrinfo(const char *name, const struct addrinfo *pai) | 1146 | _dns_getaddrinfo(const char *name, const struct addrinfo *pai, |
1147 | const struct __res_state *_resp) | ||
1146 | { | 1148 | { |
1147 | struct addrinfo *ai; | 1149 | struct addrinfo *ai; |
1148 | querybuf *buf, *buf2; | 1150 | querybuf *buf, *buf2; |
@@ -1168,14 +1170,39 @@ _dns_getaddrinfo(const char *name, const struct addrinfo *pai) | |||
1168 | 1170 | ||
1169 | switch (pai->ai_family) { | 1171 | switch (pai->ai_family) { |
1170 | case AF_UNSPEC: | 1172 | case AF_UNSPEC: |
1171 | /* prefer IPv6 */ | 1173 | if (_resp->family[0] == -1) { |
1174 | /* prefer IPv4 by default*/ | ||
1175 | q.qclass = C_IN; | ||
1176 | q.qtype = T_A; | ||
1177 | q.answer = buf->buf; | ||
1178 | q.anslen = sizeof(buf->buf); | ||
1179 | q.next = &q2; | ||
1180 | q2.qclass = C_IN; | ||
1181 | q2.qtype = T_AAAA; | ||
1182 | q2.answer = buf2->buf; | ||
1183 | q2.anslen = sizeof(buf2->buf); | ||
1184 | break; | ||
1185 | } | ||
1186 | |||
1187 | /* respect user supplied order */ | ||
1172 | q.qclass = C_IN; | 1188 | q.qclass = C_IN; |
1173 | q.qtype = T_AAAA; | 1189 | if (_resp->family[0] == AF_INET6) |
1190 | q.qtype = T_AAAA; | ||
1191 | else | ||
1192 | q.qtype = T_A; | ||
1174 | q.answer = buf->buf; | 1193 | q.answer = buf->buf; |
1175 | q.anslen = sizeof(buf->buf); | 1194 | q.anslen = sizeof(buf->buf); |
1195 | if (_resp->family[1] == -1) { | ||
1196 | q.next = NULL; | ||
1197 | break; | ||
1198 | } | ||
1176 | q.next = &q2; | 1199 | q.next = &q2; |
1200 | |||
1177 | q2.qclass = C_IN; | 1201 | q2.qclass = C_IN; |
1178 | q2.qtype = T_A; | 1202 | if (_resp->family[1] == AF_INET6) |
1203 | q2.qtype = T_AAAA; | ||
1204 | else | ||
1205 | q2.qtype = T_A; | ||
1179 | q2.answer = buf2->buf; | 1206 | q2.answer = buf2->buf; |
1180 | q2.anslen = sizeof(buf2->buf); | 1207 | q2.anslen = sizeof(buf2->buf); |
1181 | break; | 1208 | break; |