Hello,
In a simple macOS tool, I'm trying to bind a socket to the default interface like "en0" or a VPN interface like "utun5" to make the socket send the data only through that interface.
int idx = (int)if_nametoindex("utun5"); if (setsockopt(sock, IPPROTO_IP, IP_BOUND_IF, &idx, sizeof(idx)) == -1) { perror("setsockopt"); exit(1); }
The method setsockopt succeeds however the data doesn't go through the bound interface, but it goes through the default interface like if there has been no binding at all.
I tried also with libcurl, which is based on sockets, but the data goes through the default interface like before, even if the method succeed.
if (curl_easy_setopt(curlH, CURLOPT_INTERFACE, "utun5") != CURLE_OK) { perror("CURLOPT_INTERFACE"); exit(1); }
May someone suggest how to bind an interface to a socket in a way that makes all the data transmitted by that socket go only through the bound interface?
Any constructive suggestion is very welcome. Thank you!
Best regards,
Luca Severini