Note that this is for creating a custom network protocol. So we don't expect these interfaces to have any Internet connectivity.
In fact, we want to be able to enumerate the interfaces even when the cable is disconnected.
So we cannot use use the method described in this thread - which only works for interfaces which have a cable connection:
Getting NWInterface for ...
Alternatively, is there a way to get an NWInterface from a SCNetworkInterfaceRef (obtained via SCNetworkServiceCopyAll() -> SCNetworkServiceGetInterface())?
There is the undocumented nw_interface_create_with_name() - but I'm not sure if that's a good idea.
Thanks.
Devendra.
OK. In that case use SCNetworkInterfaceCopyAll. That API was specifically designed to return a list of known network ports and their user-visible names (using SCNetworkInterfaceGetLocalizedDisplayName), something that’s very hard to do with any other API.Typical user workflow often involves the user wanting to select the
interface in our software even when no device is physically connected
to the interface - because they know where they will be connecting the
devices later on.
You only need NWEthernetChannel when the user actually tries to use the interface. At that point, if you detect that there’s no IPv6 link local address, you can inform the user of the problem.
If you specifically want to determine whether the problem is that nothing is plugged in, use the dynamic store to check for the kSCPropNetLinkActive property in the interface’s kSCEntNetLink entity. For example:
Code Block % scutil > show State:/Network/Interface/en7/Link <dictionary> { Active : FALSE }
[Although in a real app you’d do this in code rather relying on scutil.]
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"