ifaddrs.h contains some useful information if you want to work with sockets. Using getifaddrs will enumerate all interfaces and the IP addresses they are bound to. However Swift does not include this header in either Darwin or Glibc.
Using Swift 3’s SPM, a first attempt would be to define a system module package like this:
While this is OK for SPM, Xcode will give the following error message:
[…]Sources/Cifaddrs/include/Cifaddrs.h:1:9: Include of non-modular header inside framework module 'Cifaddrs'
Note that setting CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES doesn’t affect Swift compiler.
That got me thinking. In the header file I’m apparently not allowed to import non-modular header files. However in the implementation file, I could just forward to the actual implementation.
Sources/Cifaddrs/include/Cifaddrs.h:
Sources/Cifaddrs/Cifaddrs.c:
From Swift, enumerating the interfaces looks like this:
And with Swift 3’s sequence the result can be transformed in a sequence: