aboutsummaryrefslogtreecommitdiff
path: root/lib/connect.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2010-11-30 06:20:54 +0100
committerYang Tse <yangsita@gmail.com>2010-11-30 06:20:54 +0100
commitf6f5d7874f6a890f2626195f169abcbfc785b220 (patch)
tree94039bb2a957ead238095ddb5a67bec225373e67 /lib/connect.c
parent5db0a412ff6972e51ccddaf1e8d6a27c8de4990f (diff)
fix getinfo CURLINFO_LOCAL* for reused connections
Diffstat (limited to 'lib/connect.c')
-rw-r--r--lib/connect.c58
1 files changed, 23 insertions, 35 deletions
diff --git a/lib/connect.c b/lib/connect.c
index 88fb7eb76..95033fa81 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -541,6 +541,9 @@ static bool getaddressinfo(struct sockaddr* sa, char* addr,
#ifdef ENABLE_IPV6
struct sockaddr_in6* si6 = NULL;
#endif
+#if defined(HAVE_SYS_UN_H) && defined(AF_UNIX)
+ struct sockaddr_un* su = NULL;
+#endif
switch (sa->sa_family) {
case AF_INET:
@@ -561,6 +564,13 @@ static bool getaddressinfo(struct sockaddr* sa, char* addr,
*port = us_port;
break;
#endif
+#if defined(HAVE_SYS_UN_H) && defined(AF_UNIX)
+ case AF_UNIX:
+ su = (struct sockaddr_un*)sa;
+ snprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path);
+ *port = 0;
+ break;
+#endif
default:
addr[0] = '\0';
*port = 0;
@@ -600,7 +610,7 @@ void Curl_updateconninfo(struct connectdata *conn, curl_socket_t sockfd)
}
if(!getaddressinfo((struct sockaddr*)&ssrem,
- info->ip, &info->port)) {
+ info->primary_ip, &info->primary_port)) {
error = ERRNO;
failf(data, "ssrem inet_ntop() failed with errno %d: %s",
error, Curl_strerror(conn, error));
@@ -608,7 +618,7 @@ void Curl_updateconninfo(struct connectdata *conn, curl_socket_t sockfd)
}
if(!getaddressinfo((struct sockaddr*)&ssloc,
- info->localip, &info->localport)) {
+ info->local_ip, &info->local_port)) {
error = ERRNO;
failf(data, "ssloc inet_ntop() failed with errno %d: %s",
error, Curl_strerror(conn, error));
@@ -802,11 +812,6 @@ singleipconnect(struct connectdata *conn,
struct SessionHandle *data = conn->data;
curl_socket_t sockfd;
CURLcode res = CURLE_OK;
- const void *iptoprint;
- struct sockaddr_in * const sa4 = (void *)&addr.sa_addr;
-#ifdef ENABLE_IPV6
- struct sockaddr_in6 * const sa6 = (void *)&addr.sa_addr;
-#endif
*sockp = CURL_SOCKET_BAD;
@@ -855,37 +860,20 @@ singleipconnect(struct connectdata *conn,
sa6->sin6_scope_id = conn->scope;
#endif
- /* FIXME: do we have Curl_printable_address-like with struct sockaddr* as
- argument? */
-#if defined(HAVE_SYS_UN_H) && defined(AF_UNIX)
- if(addr.family == AF_UNIX) {
- infof(data, " Trying %s... ",
- ((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);
+ /* store remote address and port used in this connection attempt */
+ if(!getaddressinfo((struct sockaddr*)&addr.sa_addr,
+ data->info.primary_ip, &data->info.primary_port)) {
+ error = ERRNO;
+ failf(data, "sa_addr inet_ntop() failed with errno %d: %s",
+ error, Curl_strerror(conn, error));
}
- else
-#endif
- {
+ strcpy(conn->ip_addr_str, data->info.primary_ip);
+ infof(data, " Trying %s... ", conn->ip_addr_str);
+
#ifdef ENABLE_IPV6
- if(addr.family == AF_INET6) {
- iptoprint = &sa6->sin6_addr;
- conn->bits.ipv6 = TRUE;
- }
- else
+ if(addr.family == AF_INET6)
+ conn->bits.ipv6 = TRUE;
#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);
- }
- }
if(data->set.tcp_nodelay)
tcpnodelay(conn, sockfd);