Need to bind `nw_parameters_create_secure_tcp` with specific utun interface.

Hi Team,

I am utilizing the nw_parameters_create_secure_tcp in Objective-C to establish a TCP connection. However, I would like the connection to go through a specific utun interface.

I attempted to use the following method for binding:

nw_parameters_require_interface(nw_parameters_t parameters,
                                _Nullable nw_interface_t interface);

Unfortunately, I haven't found any API that can convert a utun interface name or index to an nw_interface_t object. Both nw_interface_create_with_index and nw_interface_create_with_name are private methods.

I also tried using nw_path_monitor_set_update_handler and nw_path_enumerate_interfaces, but they did not return the utun interface.

Could you please suggest how I can obtain the utun interface as an nw_interface_t?

Answered by DTS Engineer in 768264022

Could you please suggest how I can obtain the utun interface as an nw_interface_t?

I don’t know of any supported way to do this in the C API )-: [1]

Given that you know the address of your interface, could you attack this problem by binding the connection’s local endpont to that address (using nw_parameters_set_local_endpoint).

Share and Enjoy

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

[1] With the Swift API you can use the following trick:

let ep = NWEndpoint.hostPort(host: "::1%en0", port: 12345)
guard let interface = ep.interface else { … handle failure … }
… use `interface` …

The same trick doesn’t work in the C API because there’s no nw_endpoint_copy_interface API.

Accepted Answer

Could you please suggest how I can obtain the utun interface as an nw_interface_t?

I don’t know of any supported way to do this in the C API )-: [1]

Given that you know the address of your interface, could you attack this problem by binding the connection’s local endpont to that address (using nw_parameters_set_local_endpoint).

Share and Enjoy

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

[1] With the Swift API you can use the following trick:

let ep = NWEndpoint.hostPort(host: "::1%en0", port: 12345)
guard let interface = ep.interface else { … handle failure … }
… use `interface` …

The same trick doesn’t work in the C API because there’s no nw_endpoint_copy_interface API.

Need to bind `nw_parameters_create_secure_tcp` with specific utun interface.
 
 
Q