aboutsummaryrefslogtreecommitdiff
path: root/lib/connect.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/connect.c')
-rw-r--r--lib/connect.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/connect.c b/lib/connect.c
index 4adc7f35a..43e17aa63 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -523,6 +523,50 @@ static bool trynextip(struct connectdata *conn,
return TRUE;
}
+/* retrieves ip address and port from a sockaddr structure */
+static void getaddressinfo(struct sockaddr* sa, char* addr,
+ long* port)
+{
+ struct sockaddr_in* si = NULL;
+#ifdef ENABLE_IPV6
+ struct sockaddr_in6* si6 = NULL;
+#endif
+
+ switch (sa->sa_family) {
+ case AF_INET:
+ si = (struct sockaddr_in*) sa;
+ Curl_inet_ntop(sa->sa_family, &(si->sin_addr), addr, MAX_IPADR_LEN);
+ *port = ntohs(si->sin_port);
+ break;
+#ifdef ENABLE_IPV6
+ case AF_INET6:
+ si6 = (struct sockaddr_in6*)sa;
+ Curl_inet_ntop(sa->sa_family, &(si6->sin6_addr), addr, MAX_IPADR_LEN);
+ *port = ntohs(si6->sin6_port);
+ break;
+#endif
+ default:
+ addr[0] = '\0';
+ *port = 0;
+ }
+}
+
+/* retrieves the start/end point information of a socket of an established
+ connection */
+void Curl_updateconninfo(curl_socket_t sockfd, struct PureInfo* info)
+{
+ struct Curl_sockaddr_storage ssrem;
+ struct Curl_sockaddr_storage ssloc;
+
+ socklen_t len = sizeof(struct Curl_sockaddr_storage);
+
+ getpeername(sockfd, (struct sockaddr*) &ssrem, &len);
+ getsockname(sockfd, (struct sockaddr*) &ssloc, &len);
+
+ getaddressinfo((struct sockaddr*)&ssrem, info->ip, &info->port);
+ getaddressinfo((struct sockaddr*)&ssloc, info->localip, &info->localport);
+}
+
/*
* Curl_is_connected() is used from the multi interface to check if the
* firstsocket has connected.
@@ -577,6 +621,8 @@ CURLcode Curl_is_connected(struct connectdata *conn,
*connected = TRUE;
Curl_pgrsTime(data, TIMER_CONNECT); /* connect done */
Curl_verboseconnect(conn);
+ Curl_updateconninfo(sockfd, &(data->info));
+
return CURLE_OK;
}
/* nope, not connected for real */
@@ -866,6 +912,7 @@ singleipconnect(struct connectdata *conn,
/* we are connected, awesome! */
*connected = TRUE; /* this is a true connect */
infof(data, "connected\n");
+ Curl_updateconninfo(sockfd, &(data->info));
return sockfd;
}
else if(WAITCONN_TIMEOUT == rc)