aboutsummaryrefslogtreecommitdiff
path: root/lib/connect.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2008-11-03 16:24:56 +0000
committerDaniel Stenberg <daniel@haxx.se>2008-11-03 16:24:56 +0000
commitd0b8b5a1990a31f37fcab925cb8b59bee958d41d (patch)
tree01f76987f143f68e2a4633f7cae8dcdc4b22a556 /lib/connect.c
parentefe2ce3647b751d137c105c3b08b8290fb1f801c (diff)
- Bug #2218480 (http://curl.haxx.se/bug/view.cgi?id=2218480) pointed out a
problem with my CURLINFO_PRIMARY_IP fix from October 7th that caused a NULL pointer read. I also took the opportunity to clean up this logic (storing of the connection's IP address) somewhat as we had it stored in two different places and ways previously and they are now unified.
Diffstat (limited to 'lib/connect.c')
-rw-r--r--lib/connect.c30
1 files changed, 8 insertions, 22 deletions
diff --git a/lib/connect.c b/lib/connect.c
index 7fc808e86..b602731fe 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -555,25 +555,6 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
return rc;
}
-CURLcode Curl_store_ip_addr(struct connectdata *conn)
-{
- char addrbuf[256];
- Curl_printable_address(conn->ip_addr, addrbuf, sizeof(addrbuf));
-
- /* save the string */
- Curl_safefree(conn->ip_addr_str);
- conn->ip_addr_str = strdup(addrbuf);
- if(!conn->ip_addr_str)
- return CURLE_OUT_OF_MEMORY; /* FAIL */
-
-#ifdef PF_INET6
- if(conn->ip_addr->ai_family == PF_INET6)
- conn->bits.ipv6 = TRUE;
-#endif
-
- return CURLE_OK;
-}
-
/* Used within the multi interface. Try next IP address, return TRUE if no
more address exists or error */
static bool trynextip(struct connectdata *conn,
@@ -600,8 +581,7 @@ static bool trynextip(struct connectdata *conn,
/* store the new socket descriptor */
conn->sock[sockindex] = sockfd;
conn->ip_addr = ai;
-
- return (bool)(Curl_store_ip_addr(conn) != CURLE_OK);
+ break;
}
ai = ai->ai_next;
}
@@ -824,21 +804,27 @@ singleipconnect(struct connectdata *conn,
((const struct sockaddr_un*)(&addr.sa_addr))->sun_path);
snprintf(data->info.ip, MAX_IPADR_LEN, "%s",
((const struct sockaddr_un*)(&addr.sa_addr))->sun_path);
+ strcpy(conn->ip_addr_str, data->info.ip);
}
else
#endif
{
#ifdef ENABLE_IPV6
- if(addr.family == AF_INET6)
+ if(addr.family == AF_INET6) {
iptoprint = &sa6->sin6_addr;
+ conn->bits.ipv6 = TRUE;
+ }
else
#endif
+ {
iptoprint = &sa4->sin_addr;
+ }
if(Curl_inet_ntop(addr.family, iptoprint, addr_buf,
sizeof(addr_buf)) != NULL) {
infof(data, " Trying %s... ", addr_buf);
snprintf(data->info.ip, MAX_IPADR_LEN, "%s", addr_buf);
+ strcpy(conn->ip_addr_str, data->info.ip);
}
}