Posted By

Zydeco on 10/11/09


Tagged

cocoa mac osx network iokit interfaces


Versions (?)

Mac OS X Network Interfaces


 / Published in: Objective C
 

Returns an array with the names of the network interfaces (en0, en1, fw0, etc) Link to the IOKit framework

  1. #import <IOKit/IOKitLib.h>
  2. #import <IOKit/network/IONetworkInterface.h>
  3.  
  4. + (NSArray*)networkInterfaces {
  5. CFMutableDictionaryRef match;
  6. NSMutableArray *arr = [NSMutableArray arrayWithCapacity:3];;
  7. io_iterator_t iter;
  8. io_registry_entry_t iface;
  9.  
  10. match = IOServiceMatching(kIONetworkInterfaceClass);
  11. IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iter);
  12.  
  13. while (iface = IOIteratorNext(iter)) {
  14. CFTypeRef ifNamePrefix, ifUnit;
  15. ifNamePrefix = IORegistryEntryCreateCFProperty(iface, CFSTR(kIOInterfaceNamePrefix), kCFAllocatorDefault, 0);
  16. ifUnit = IORegistryEntryCreateCFProperty(iface, CFSTR(kIOInterfaceUnit), kCFAllocatorDefault, 0);
  17. [arr addObject:[NSString stringWithFormat:@"%@%@", ifNamePrefix, ifUnit]];
  18. CFRelease(ifNamePrefix);
  19. CFRelease(ifUnit);
  20. IOObjectRelease(iface);
  21. }
  22. IOObjectRelease(iter);
  23. return arr;
  24. }

Report this snippet  

You need to login to post a comment.