GNURLINFO_LOCAL_IP(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

hey bestie πŸ’– welcome to GNURLINFO_LOCAL_IP(3), straight out of the curl_easy_getinfo options manual β€” and no cap, this one is a little lookup queen for finding the local IP address of your last connection. Let’s get into it ✨

🌸 NAME 🌸

CURLINFO_LOCAL_IP β€” get the local IP address of the last connection. periodt πŸ’…

✨ SYNOPSIS ✨

okay so you include this header and call it like this, exactly:

#include <gnurl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_LOCAL_IP, char **ip);

πŸ¦‹ DESCRIPTION πŸ¦‹

Pass a pointer to a char pointer so you can receive the pointer to a null-terminated string holding the IP address of the local end of the most recent connection done with this curl handle. This string may be IPv6 when that is enabled πŸ‘‘

Important vibe check: you get a pointer to a memory area that will be re-used at the next request, so you need to copy the string if you want to keep the information. Like, if you’re obsessed with that IP and want it to stay yours, copy it πŸ’–

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. So do not touch the free button on that one, bestie, fr fr πŸ™ˆ

🌈 PROTOCOLS 🌈

All ✨

πŸŽ€ EXAMPLE πŸŽ€

Here’s the code vibe, with everything exactly where it belongs:

{
  char *ip;

  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");

  /* Perform the request, res will get the return code */
  res = curl_easy_perform(curl);
  /* Check for errors */
  if((res == CURLE_OK) &&
     !curl_easy_getinfo(curl, CURLINFO_LOCAL_IP, &ip) && ip) {
    printf("Local IP: %s\n", ip);
  }

  /* always cleanup */
  curl_easy_cleanup(curl);
}

⭐ AVAILABILITY ⭐

Added in 7.21.0 β€” yes, that’s the exact version, iykyk 🫢

πŸ’œ RETURN VALUE πŸ’œ

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. Simple as that, bestie 😌

πŸ‘‘ SEE ALSO πŸ‘‘

go peek at these:


xoxo, your Unix bestie πŸ’– this iconic page is brought to you by libcurl 7.44.0, dated 12 Sep 2015, and it’s literally GNURLINFO_LOCAL_IP(3) β€” slay ✨

πŸ“¦ where this page comes from