Local address and port number
In almost all situations you want to let the system pick the default source IPaddress and local port number when setting up a connection.
For the rare instances when that is not good enough, libcurl featuresoverrides.
Local address
A connection created by libcurl needs to have a source IP that routes back tothis host. An application can not just randomly pick whatever IP address itwants to use and expect that to work. A network interface in the machine needsto have the IP address assigned.
You can ask libcurl to use a non-default IP address withCURLOPT_INTERFACE
.As the name hints, it is designed to get a named network interface as inputand it will then attempt to use that interface's IP address for outgoingtraffic.
The name can however instead be an IP address or a hostname, even thoughwedo not recommend using those versions.
To prevent libcurl from guessing what kind of input that is provided, prefixthe interface name with "if!", to make sure the name is not mistaken for ahostname.
Similarly, you prefix the provided name with "host!" to insist the address isa hostname or IP number.
Local port number
By default, 16 bit random source local port numbers are used for connections,from the so calledephemeral port range. An application can ask for aspecific port range to be used with theCURLOPT_LOCALPORT
andCURLOPT_LOCALPORTRANGE
options. Since port numbers are finite resources,narrowing the selection of ports to select from will increase the risk thatthe connection cannot be setup if none of the attempted port numbers arecurrently available to be used.