cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Patch to get ip address last requested

From: Jason Pump <jpump_at_mindspring.com>
Date: Tue, 19 Jul 2005 20:33:41 -0700

Here is the gist of a patch to get the ip address last requested in a curl
easy handle, *IF* you are using the curl multi handle and calling
curl_multi_perform(). If I get some time I will clean it up if people think
it's worthwhile. I definitely don't think this is the ideal way to get the
ip address, but I couldn't find anything else. If there is a better way if
someone can outline it I will see what I can do. I might have posted this
already, sorry if it's a dupe.

If anyone if familiar with the various host caches I have a few questions
for you if you're up to it. Also if anyone want to outline a different way
to do this I will take a look.

Jason

diff -Naur curl-7.14.0.orig/include/curl/multi.h
curl-7.14.0.mod/include/curl/multi.h
--- curl-7.14.0.orig/include/curl/multi.h 2005-04-18
04:45:13.000000000 -0700
+++ curl-7.14.0.mod/include/curl/multi.h 2005-07-14
10:02:16.000000000 -0700
@@ -126,6 +126,15 @@
  */
 CURL_EXTERN CURLM *curl_multi_init(void);

+CURL_EXTERN CURLcode curl_multi_getlastip(CURLM *multi_handle,
+ CURL *easy_handle,
+ char* cachedIp,
+ int cachedIpSize,
+ int port);
+
+
+
+
 /*
  * Name: curl_multi_add_handle()
  *
diff -Naur curl-7.14.0.orig/lib/multi.c curl-7.14.0.mod/lib/multi.c
--- curl-7.14.0.orig/lib/multi.c 2005-03-08 14:21:59.000000000 -0800
+++ curl-7.14.0.mod/lib/multi.c 2005-07-14 10:01:54.000000000 -0700
@@ -793,3 +793,50 @@
   else
     return NULL;
 }
+
+
+CURLcode curl_multi_getlastip
+(
+ CURLM *multi_handle,
+ CURL *easy_handle,
+ char* cachedIp,
+ int cachedIpSize,
+ int port
+)
+{
+
+ if ( !cachedIp ) return CURLE_FAILED_INIT;
+
+ struct Curl_multi *multi=(struct Curl_multi *)multi_handle;
+ struct SessionHandle *easy=(struct SessionHandle *)easy_handle;
+
+ cachedIp[0]=0;
+
+ struct curl_hash * hc = multi->hostcache;
+
+ if ( easy && easy->state.first_host != NULL )
+ {
+ static char entry_id[4096];
+ sprintf(entry_id, "%s:80", easy->state.first_host);
+
+ /* if ( !hc ) printf("No hostcache.\n"); */
+
+ if ( entry_id && hc )
+ {
+ int entry_len = strlen(entry_id);
+ struct Curl_dns_entry* dns = Curl_hash_pick(hc, entry_id,
entry_len+1);
+ if ( dns )
+ {
+ Curl_printable_address(dns->addr, cachedIp, cachedIpSize);
+ }
+ /* else printf("Null dns returned for %s (%d)", entry_id,
entry_len+1); */
+
+ free(entry_id);
+
+ return CURLE_OK;
+ }
+ }
+ return CURLE_FAILED_INIT;
+}
+
+

  • application/x-zip-compressed attachment: patch.zip
Received on 2005-07-20