myLC---wrote:
I would like to know how we can retrieve all the IP
addresses which are mapped to a host.
Assuming we have the URL
https://example.buzz/bingo_results/
and assuming further that there are 5 addresses mapped to
this hostname:
10.0.0.11, 10.0.0.12, 10.0.0.13,
fd0e:34f4:760f:5bd6:0123:4567:89ab:cdef,
fd0e:34f4:760f:5bd6:aaaa:bbbb:cccc:dddd
How would I get them from libcurl?
Not sure you can get them all (unless one of them
fail). But the "primary IP" could be fetched by:
char ip [5*16]; // enough for IPv6?
curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, ip);
Or try my old 'sock_snoop.c' example attached.
c:\>sock_snoop.exe -v http://www.vg.no
* STATE: INIT => CONNECT handle 0x24bb028; line 1447 (connection #-5000)
* Rebuilt URL to: www.vg.no/
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x24bb028; line 1483 (connection #0)
AF_INET: 195.88.54.16
* Trying 195.88.54.16...
* Could not set TCP_NODELAY: Descriptor is not a socket
* Immediate connect fail for 195.88.54.16: Descriptor is not a socket
AF_INET: 195.88.55.16
* Trying 195.88.55.16...
* Could not set TCP_NODELAY: Descriptor is not a socket
* Immediate connect fail for 195.88.55.16: Descriptor is not a socket
AF_INET6: 2001:67c:21e0::16
* Trying 2001:67c:21e0::16...
* Could not set TCP_NODELAY: Descriptor is not a socket
* Immediate connect fail for 2001:67c:21e0::16: Descriptor is not a socket
* Closing connection 0
* The cache now contains 0 members
* Expire cleared
--
--gv
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
static int snoop = 1;
static SOCKET getsock (void *clientp,
curlsocktype purpose,
struct curl_sockaddr *ca)
{
const struct sockaddr_in *a4 = (const struct sockaddr_in*) &ca->addr;
const struct sockaddr_in6 *a6 = (const struct sockaddr_in6*) &ca->addr;
char buf [200];
switch (ca->family)
{
case AF_INET:
printf ("AF_INET: %s\n", inet_ntop(ca->family, &a4->sin_addr, buf,
sizeof(buf)));
break;
case AF_INET6:
printf ("AF_INET6: %s\n", inet_ntop(ca->family, &a6->sin6_addr, buf,
sizeof(buf)));
break;
}
if (snoop)
return 0;
return socket (ca->family, ca->protocol, 0);
}
int main (int argc, char **argv)
{
CURL *curl = NULL;
char scheme [200+1];
char url [200+1];
int verbose = 0;
if (argc > 1 && !strcmp(argv[1],"-v"))
{
verbose = 1;
argc--;
argv++;
}
if (argc < 2 || sscanf(argv[1],"%20[^/:]://%s",scheme,url) != 2)
{
printf ("Usage: sock_snoop [-v] <scheme://URL>\n");
return (-1);
}
curl = curl_easy_init();
curl_easy_setopt (curl, CURLOPT_CONNECT_ONLY, 1);
curl_easy_setopt (curl, CURLOPT_URL, url);
curl_easy_setopt (curl, CURLOPT_OPENSOCKETFUNCTION, getsock);
curl_easy_setopt (curl, CURLOPT_VERBOSE, verbose);
curl_easy_perform (curl);
curl_easy_cleanup (curl);
return (0);
}
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html