aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Fandrich <dan@coneharvesters.com>2008-07-27 02:20:34 +0000
committerDan Fandrich <dan@coneharvesters.com>2008-07-27 02:20:34 +0000
commit432945e42218dbe479836674dbd633f5ca2b7f9f (patch)
tree1d21b34a4930244d1b1cbd86a91c4c16b509885f /lib
parent052f9ddedb345815c8700370ce2fa22e37f4de8a (diff)
Eliminate a unnecessary socket creation in Curl_getaddrinfo for an IPv4
address in an IPv6 capable libcurl.
Diffstat (limited to 'lib')
-rw-r--r--lib/hostip6.c51
1 files changed, 26 insertions, 25 deletions
diff --git a/lib/hostip6.c b/lib/hostip6.c
index dde22d1b1..0d63f7224 100644
--- a/lib/hostip6.c
+++ b/lib/hostip6.c
@@ -233,40 +233,41 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
char sbuf[NI_MAXSERV];
char *sbufptr = NULL;
char addrbuf[128];
- curl_socket_t s;
int pf;
struct SessionHandle *data = conn->data;
*waitp=0; /* don't wait, we have the response now */
- /* see if we have an IPv6 stack */
- s = socket(PF_INET6, SOCK_DGRAM, 0);
- if(s == CURL_SOCKET_BAD) {
- /* Some non-IPv6 stacks have been found to make very slow name resolves
- * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
- * the stack seems to be a non-ipv6 one. */
-
+ /*
+ * Check if a limited name resolve has been requested.
+ */
+ switch(data->set.ip_version) {
+ case CURL_IPRESOLVE_V4:
pf = PF_INET;
+ break;
+ case CURL_IPRESOLVE_V6:
+ pf = PF_INET6;
+ break;
+ default:
+ pf = PF_UNSPEC;
+ break;
}
- else {
- /* This seems to be an IPv6-capable stack, use PF_UNSPEC for the widest
- * possible checks. And close the socket again.
- */
- sclose(s);
- /*
- * Check if a more limited name resolve has been requested.
- */
- switch(data->set.ip_version) {
- case CURL_IPRESOLVE_V4:
+ if (pf != PF_INET) {
+ /* see if we have an IPv6 stack */
+ curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
+ if(s == CURL_SOCKET_BAD) {
+ /* Some non-IPv6 stacks have been found to make very slow name resolves
+ * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
+ * the stack seems to be a non-ipv6 one. */
+
pf = PF_INET;
- break;
- case CURL_IPRESOLVE_V6:
- pf = PF_INET6;
- break;
- default:
- pf = PF_UNSPEC;
- break;
+ }
+ else {
+ /* This seems to be an IPv6-capable stack, use PF_UNSPEC for the widest
+ * possible checks. And close the socket again.
+ */
+ sclose(s);
}
}