How can I detect if any network adapter is connected? I can only find examples on using NSReachability to detect an internet connection, but I want to detect even a non-internet network connection. Getting the IP-adress on eth0 should work? I’m working on Mac only.
Share
Getting a List of All IP Addresses in Apple’s Technical Note TN1145 mentions 3 methods for getting the status of the network interfaces:
System Configuration Framework: This is Apple’s recommended way and there is sample code in the TN1145. The advantage is that it provides a way to get notified of changes in the interface configuration.
Open Transport API: There is also sample code in TN1145, otherwise I cannot say much about it. (There is only “legacy” documentation on the Apple website.)
BSD sockets: This seems to be the easiest way to get the list of interfaces and to determine the connection status (if you don’t need dynamic change notifications).
The following code demonstrates how to find all IPv4 and IPv6 interfaces that are “up and running”.