CURLOPT_INTERFACE.md (2289B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_INTERFACE 5 Section: 3 6 Source: libcurl 7 Protocol: 8 - All 9 See-also: 10 - CURLOPT_SOCKOPTFUNCTION (3) 11 - CURLOPT_TCP_NODELAY (3) 12 - CURLOPT_LOCALPORT (3) 13 Added-in: 7.3 14 --- 15 16 # NAME 17 18 CURLOPT_INTERFACE - source interface for outgoing traffic 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_INTERFACE, char *interface); 26 ~~~ 27 28 # DESCRIPTION 29 30 Pass a char pointer as parameter. This sets the *interface* name to use as 31 outgoing network interface. The name can be an interface name, an IP address, 32 or a hostname. If you prefer one of these, you can use the following special 33 prefixes: 34 35 * `if!\<name\>` - Interface name 36 * `host!\<name\>` - IP address or hostname 37 * `ifhost!\<interface\>!\<host\>` - Interface name and IP address or hostname 38 39 If `if!` or `ifhost!` is specified but the parameter does not match an existing 40 interface, *CURLE_INTERFACE_FAILED* is returned from the libcurl function used 41 to perform the transfer. 42 43 libcurl does not support using network interface names for this option on 44 Windows. 45 46 We strongly advise against specifying the interface with a hostname, as it 47 causes libcurl to do a blocking name resolve call to retrieve the IP address. 48 That name resolve operation does **not** use DNS-over-HTTPS even if 49 CURLOPT_DOH_URL(3) is set. 50 51 The application does not have to keep the string around after setting this 52 option. 53 54 Using this option multiple times makes the last set string override the 55 previous ones. Set it to NULL to disable its use again. 56 57 # DEFAULT 58 59 NULL, use whatever the TCP stack finds suitable 60 61 # %PROTOCOLS% 62 63 # EXAMPLE 64 65 ~~~c 66 int main(void) 67 { 68 CURL *curl = curl_easy_init(); 69 if(curl) { 70 CURLcode res; 71 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 72 73 curl_easy_setopt(curl, CURLOPT_INTERFACE, "eth0"); 74 75 res = curl_easy_perform(curl); 76 77 curl_easy_cleanup(curl); 78 } 79 } 80 ~~~ 81 82 # HISTORY 83 84 The `if!` and `host!` syntax was added in 7.24.0. 85 86 The `ifhost!` syntax was added in 8.9.0. 87 88 # %AVAILABILITY% 89 90 # RETURN VALUE 91 92 curl_easy_setopt(3) returns a CURLcode indicating success or error. 93 94 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 95 libcurl-errors(3).