CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_PRIMARY_IP, char **ip);
DESCRIPTIONPass a pointer to a char pointer to receive the pointer to a zero-terminated string holding the IP address of the most recent connection done with this curl handle. This string may be IPv6 when that is enabled. Note that you get a pointer to a memory area that will be re-used at next request so you need to copy the string if you want to keep the information.
The ip pointer will be NULL or pointing to private memory you MUST NOT free - it gets freed when you call curl_easy_cleanup(3) on the corresponding CURL handle.