How to retrieve local IP address from nw_interface_t?

Currently I see methods to get the name, index, and type of nw_interface_t objects. Is there a way to get the IP addresses attached to that interface?


I tried nw_path's nw_path_copy_effective_local_endpoint inside of a nw_path_monitor callback, but it always returns null.

Replies

To be clear, there’s no such thing as a “local IP address” for an interface. An interface has a set of local IP addresses, with an arbitrary mixture of IPv4 and IPv6.

The easiest way to get that set is to call

nw_interface_get_name
to get the BSD name for the interface and then use that to filter the results of
getidaddrs
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"