CURLOPT_INTERFACE(3)

πŸ’… CURLOPT_INTERFACE(3) β€” aka "pick your outgoing vibe" ✨

okay bestie, so this one's from the libcurl Library Functions Manual and it's literally about choosing which network interface your traffic leaves from. it's giving "main character picks her own exit" energy πŸŽ€


✨ NAME ✨

CURLOPT_INTERFACE β€” the source interface for your outgoing traffic πŸ¦‹

✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_INTERFACE, char *interface);

✨ DESCRIPTION ✨

so you pass in a char pointer as the parameter, and it sets the interface name to use as the outgoing network interface. easy!! the name can be an interface name, an IP address, or a hostname. and if you're feeling picky and want to be explicit about which of those you mean, there are these special prefixes you can slap on the front:

  • if!<name> β€” interface name πŸ’–
  • host!<name> β€” IP address or hostname 🌸
  • ifhost!<interface>!<host> β€” interface name and IP address or hostname together 🫢
⚠️ if you specify if! or ifhost! but the parameter doesn't match an existing interface, you get CURLE_INTERFACE_FAILED back from whichever libcurl function you used to actually do the transfer. sad but true 😭

ok so important thing: libcurl does not support using network interface names for this option on Windows. ngl, that's just how it is πŸ’€

and we strongly advise against specifying the interface with a hostname, because it makes libcurl do a blocking name resolve call to get the IP address. also β€” that name resolve operation does not use DNS-over-HTTPS even if CURLOPT_DOH_URL(3) is set. so like, yeah, don't do that πŸ™ˆ

good news though: the application does not have to keep the string around after setting this option. set it and forget it, slay ✨

also if you use this option multiple times, the last set string overrides the previous ones. and setting it to NULL disables its use again. periodt πŸ’…

✨ DEFAULT ✨

NULL, which means: use whatever the TCP stack finds suitable πŸ‘‘

✨ PROTOCOLS ✨

this functionality affects all supported protocols, no cap 🌈

✨ EXAMPLE ✨

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_INTERFACE, "eth0");

    result = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
  }
}

✨ HISTORY ✨

  • the if! and host! syntax was added in 7.24.0 πŸŽ€
  • the ifhost! syntax was added in 8.9.0 πŸ¦‹

✨ AVAILABILITY ✨

added in curl 7.3 πŸ’–

✨ RETURN VALUE ✨

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

CURLE_OK (0) means everything was OK βœ… β€” non-zero means an error occurred 😭, see libcurl-errors(3).

✨ SEE ALSO ✨


k that's the whole thing bestie, go pick your interface and thrive πŸ‘‘πŸ’œ β€” this lil page is from libcurl, dated 2026-10-12, mwah 🫢

πŸ“¦ where this page comes from