xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_INTERFACE.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_INTERFACE
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerProtocol:
8*6236dae4SAndroid Build Coastguard Worker  - All
9*6236dae4SAndroid Build Coastguard WorkerSee-also:
10*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_SOCKOPTFUNCTION (3)
11*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_TCP_NODELAY (3)
12*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_LOCALPORT (3)
13*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.3
14*6236dae4SAndroid Build Coastguard Worker---
15*6236dae4SAndroid Build Coastguard Worker
16*6236dae4SAndroid Build Coastguard Worker# NAME
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard WorkerCURLOPT_INTERFACE - source interface for outgoing traffic
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker~~~c
23*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
24*6236dae4SAndroid Build Coastguard Worker
25*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_INTERFACE, char *interface);
26*6236dae4SAndroid Build Coastguard Worker~~~
27*6236dae4SAndroid Build Coastguard Worker
28*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard WorkerPass a char pointer as parameter. This sets the *interface* name to use as
31*6236dae4SAndroid Build Coastguard Workeroutgoing network interface. The name can be an interface name, an IP address,
32*6236dae4SAndroid Build Coastguard Workeror a hostname. If you prefer one of these, you can use the following special
33*6236dae4SAndroid Build Coastguard Workerprefixes:
34*6236dae4SAndroid Build Coastguard Worker
35*6236dae4SAndroid Build Coastguard Worker* `if!\<name\>` - Interface name
36*6236dae4SAndroid Build Coastguard Worker* `host!\<name\>` - IP address or hostname
37*6236dae4SAndroid Build Coastguard Worker* `ifhost!\<interface\>!\<host\>` - Interface name and IP address or hostname
38*6236dae4SAndroid Build Coastguard Worker
39*6236dae4SAndroid Build Coastguard WorkerIf `if!` or `ifhost!` is specified but the parameter does not match an existing
40*6236dae4SAndroid Build Coastguard Workerinterface, *CURLE_INTERFACE_FAILED* is returned from the libcurl function used
41*6236dae4SAndroid Build Coastguard Workerto perform the transfer.
42*6236dae4SAndroid Build Coastguard Worker
43*6236dae4SAndroid Build Coastguard Workerlibcurl does not support using network interface names for this option on
44*6236dae4SAndroid Build Coastguard WorkerWindows.
45*6236dae4SAndroid Build Coastguard Worker
46*6236dae4SAndroid Build Coastguard WorkerWe strongly advise against specifying the interface with a hostname, as it
47*6236dae4SAndroid Build Coastguard Workercauses libcurl to do a blocking name resolve call to retrieve the IP address.
48*6236dae4SAndroid Build Coastguard WorkerThat name resolve operation does **not** use DNS-over-HTTPS even if
49*6236dae4SAndroid Build Coastguard WorkerCURLOPT_DOH_URL(3) is set.
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard WorkerThe application does not have to keep the string around after setting this
52*6236dae4SAndroid Build Coastguard Workeroption.
53*6236dae4SAndroid Build Coastguard Worker
54*6236dae4SAndroid Build Coastguard WorkerUsing this option multiple times makes the last set string override the
55*6236dae4SAndroid Build Coastguard Workerprevious ones. Set it to NULL to disable its use again.
56*6236dae4SAndroid Build Coastguard Worker
57*6236dae4SAndroid Build Coastguard Worker# DEFAULT
58*6236dae4SAndroid Build Coastguard Worker
59*6236dae4SAndroid Build Coastguard WorkerNULL, use whatever the TCP stack finds suitable
60*6236dae4SAndroid Build Coastguard Worker
61*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
64*6236dae4SAndroid Build Coastguard Worker
65*6236dae4SAndroid Build Coastguard Worker~~~c
66*6236dae4SAndroid Build Coastguard Workerint main(void)
67*6236dae4SAndroid Build Coastguard Worker{
68*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
69*6236dae4SAndroid Build Coastguard Worker  if(curl) {
70*6236dae4SAndroid Build Coastguard Worker    CURLcode res;
71*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_INTERFACE, "eth0");
74*6236dae4SAndroid Build Coastguard Worker
75*6236dae4SAndroid Build Coastguard Worker    res = curl_easy_perform(curl);
76*6236dae4SAndroid Build Coastguard Worker
77*6236dae4SAndroid Build Coastguard Worker    curl_easy_cleanup(curl);
78*6236dae4SAndroid Build Coastguard Worker  }
79*6236dae4SAndroid Build Coastguard Worker}
80*6236dae4SAndroid Build Coastguard Worker~~~
81*6236dae4SAndroid Build Coastguard Worker
82*6236dae4SAndroid Build Coastguard Worker# HISTORY
83*6236dae4SAndroid Build Coastguard Worker
84*6236dae4SAndroid Build Coastguard WorkerThe `if!` and `host!` syntax was added in 7.24.0.
85*6236dae4SAndroid Build Coastguard Worker
86*6236dae4SAndroid Build Coastguard WorkerThe `ifhost!` syntax was added in 8.9.0.
87*6236dae4SAndroid Build Coastguard Worker
88*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
89*6236dae4SAndroid Build Coastguard Worker
90*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
91*6236dae4SAndroid Build Coastguard Worker
92*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK on success or
93*6236dae4SAndroid Build Coastguard WorkerCURLE_OUT_OF_MEMORY if there was insufficient heap space.
94