From 930a45e7a93c964ec224bdddb59f97479b7e4a5d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 6 Jun 2008 17:33:35 +0000 Subject: - Added CURLINFO_PRIMARY_IP as a new information retrievable with curl_easy_getinfo. It returns a pointer to a string with the most recently used IP address. Modified test case 500 to also verify this feature. The implementing of this feature was sponsored by Lenny Rachitsky at NeuStar. --- lib/connect.c | 9 +++++++-- lib/getinfo.c | 4 ++++ lib/urldata.h | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/connect.c b/lib/connect.c index b3928ef1e..e398f61fb 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -775,9 +775,12 @@ singleipconnect(struct connectdata *conn, /* 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) + if(addr->family==AF_UNIX) { infof(data, " Trying %s... ", ((const struct sockaddr_un*)(&addr->addr))->sun_path); + snprintf(data->info.ip, MAX_IPADR_LEN, "%s", + ((const struct sockaddr_un*)(&addr->addr))->sun_path); + } else #endif { @@ -789,8 +792,10 @@ singleipconnect(struct connectdata *conn, iptoprint = &((const struct sockaddr_in*)(&addr->addr))->sin_addr; if(Curl_inet_ntop(addr->family, iptoprint, addr_buf, - sizeof(addr_buf)) != NULL) + sizeof(addr_buf)) != NULL) { infof(data, " Trying %s... ", addr_buf); + snprintf(data->info.ip, MAX_IPADR_LEN, "%s", addr_buf); + } } if(data->set.tcp_nodelay) diff --git a/lib/getinfo.c b/lib/getinfo.c index 078154246..bef2ebac4 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -210,6 +210,10 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) option had been enabled! */ *param_charp = data->info.wouldredirect; break; + case CURLINFO_PRIMARY_IP: + /* Return the ip address of the most recent (primary) connection */ + *param_charp = data->info.ip; + break; default: return CURLE_BAD_FUNCTION_ARGUMENT; } diff --git a/lib/urldata.h b/lib/urldata.h index fa93a6454..1f9d3ebd2 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -48,6 +48,8 @@ #define CURL_DEFAULT_USER "anonymous" #define CURL_DEFAULT_PASSWORD "ftp@example.com" +#define MAX_IPADR_LEN (4*9) /* should be enough to hold the longest ipv6 one */ + #include "cookie.h" #include "formdata.h" @@ -1036,6 +1038,9 @@ struct PureInfo { long numconnects; /* how many new connection did libcurl created */ char *contenttype; /* the content type of the object */ char *wouldredirect; /* URL this would've been redirected to if asked to */ + char ip[MAX_IPADR_LEN]; /* this buffer gets the numerical ip version stored + at the connect *attempt* so it will get the last + tried connect IP even on failures */ }; -- cgit v1.2.3