CURLOPT_DNS_LOCAL_IP4(3)

πŸ’… CURLOPT_DNS_LOCAL_IP4(3) β€” bestie edition

okay so this is a page from the Library Functions Manual (libcurl's corner of it, specifically), and it's all about CURLOPT_DNS_LOCAL_IP4. welcome to the DNS binding lore πŸŽ€


✨ NAME ✨

CURLOPT_DNS_LOCAL_IP4 β€” the IPv4 address you want your DNS resolves to bind to. yes, bind. it's giving "i have a specific network interface and i'm gonna use it" πŸ’…


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DNS_LOCAL_IP4, char *address);

like, that's the whole vibe. curl_easy_setopt + your handle + this option + an address and you're off πŸ¦‹


✨ DESCRIPTION ✨

So what this does: it sets the local IPv4 address that the resolver should bind to. the argument needs to be of type char * and it should contain a single numerical IPv4 address as a string β€” like, an actual dotted-quad address, not a hostname, not a nickname, not vibes.

You can set this option to NULL to use the default setting, which is "do not bind to a specific IP address". back to the group chat default, no cap.

Good news for your memory management era: the application does not have to keep the string around after setting this option. libcurl takes what it needs, you can let the string go. mental load? released. 🫢

And if you set this option multiple times? the last set string overrides the previous ones. last one wins, main character energy. set it to NULL to disable its use again β€” iconique, reversible, we love a toggle.


✨ DEFAULT ✨

NULL

(as in: no binding, default behaviour, the unbothered state 😌)


✨ PROTOCOLS ✨

This functionality affects all supported protocols. every single one. ate. πŸ”₯


✨ EXAMPLE ✨

here's the whole thing in action, copying it exactly because bestie we do not paraphrase code:

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
    curl_easy_setopt(curl, CURLOPT_DNS_LOCAL_IP4, "192.168.0.14");
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
}

look at her go 😭 192.168.0.14 is the local IP, https://example.com/foo.bin is the target, curl_easy_perform does the thing, curl_easy_cleanup cleans up. no leaks, no drama. 🌸


✨ NOTES ✨

⚠️ important caveat time, lowkey crucial: this option requires that libcurl was built with a resolver backend that supports this operation. and the c-ares backend is the only such one. so if your libcurl wasn't built against c-ares, this option is not gonna do the cute thing you want. check your build before you come for her πŸ’€

✨ AVAILABILITY ✨

Added in curl 7.33.0 ⭐ (a classic, honestly, she's been around)


✨ RETURN VALUE ✨

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (which is 0) means everything was OK πŸ’–. non-zero means an error occurred β€” see libcurl-errors(3) for the full list of what went wrong, iykyk.


✨ SEE ALSO ✨

(the DNS-adjacent besties. go read them too, they're all part of the same friend group 🌈)


okay that's the whole page, mwah πŸ’‹ this was libcurl, dated 2026-10-12, and the page you just read is CURLOPT_DNS_LOCAL_IP4(3) β€” go bind some DNS resolves responsibly, bestie πŸ§šβ€β™€οΈπŸ’œ

πŸ“¦ where this page comes from