The "advances in networking" talks for WWDC2019 had this example of using NWEthernetChannel to monitor a custom (non-IP) protocol. This is for MacOS.
import Foundation
import Network
let path = NWPathMonitor(requiredInterfaceType: .wiredEthernet).currentPath
guard let interface = path.availableInterfaces.first else {
fatalError("not connected to Internet")
}
let channel = NWEthernetChannel(on: interface, etherType: 0xB26E)
For my application I need to use a NWEthernetChannel to monitor a custom protocol (actually Cisco Discovery Protocol and/or Link-layer discovery protocol) on an Ethernet link which does not have IP Internet connectivity (but it does have physical link to a switch). NWPath appears to only give me a NWInterface struct if it is a valid path to the Internet.
How can I get a list of NWInterface Structs on the Mac without having a valid Internet path?
In my particular use case I'm only interested in .wiredEthernet.
Something as simple as getting a full array of all NWInterfaces on a box would be sufficient, but so far the only way to "vend" NWInterfaces I've found is with NWPathMonitor, which seems to require IP connectivity.
You can get a
NWIntferfaceif you know its corresponding BSD name. The documentation ofIPv4Address.init(_:)says that you can specify the name of an interface after the IP Address, separated by%.You can only find this documentation in the generated swift interface, not on the website.
The
SystemConfigurationframework provides the functionality to get a list of all interfaces with their corresponding BSD names.This works well but it feels like a workaround. I wish Network.framework would provide a better option to get all interfaces.