How IP_BOUND_IF works to bind a socket to a specific interface?

there is few document on explain how IP_BOUND_IF works. I use the following code to specific interface to sending my data , where on a device has both wifi and vpn.

const char* device_name = "pdp_ip0";
int interfaceIndex = if_nametoindex(device_name);

int res = setsockopt(socketfd, IPPROTO_IP, IP_BOUND_IF, &interfaceIndex,
                       sizeof(interfaceIndex));

the res results 0 , but socket still send data via utun, witch is a vpn interface

Do not hard-code BSD interface names, like pdp_ip0. It will end badly.

I have a bunch of backstory about this in the various posts linked to from Extra-ordinary Networking.

socket still send data via utun, witch is a vpn interface

That can happen if the VPN sets includeAllNetworks.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How IP_BOUND_IF works to bind a socket to a specific interface?
 
 
Q