So, to wrap this up, I finally got a look at exploring the system configuration API. As always, as soon as you know how it is not so difficult.
@ 0xced - Thanks for pointing me in the right direction. I would support your answer, but I do not have enough reputation to do this.
This is my solution for anyone who is curious or in the same situation. It includes digging into dynamic storage. See this for API information. You can view information stored in dynamic storage using the scutil command-line utility (see X-man-page: // 8 / scutil).
Here are my steps. First, you need a session:
SCDynamicStoreRef storeRef = SCDynamicStoreCreate(NULL, (CFStringRef)@"FindCurrentInterfaceIpMac", NULL, NULL);
Then I try to get the main interface (e.g. en1):
CFPropertyListRef global = SCDynamicStoreCopyValue (storeRef,CFSTR("State:/Network/Global/IPv4")); NSString *primaryInterface = [(__bridge NSDictionary *)global valueForKey:@"PrimaryInterface"];
Finally, I am building a line containing the interface in order to be able to request the correct key. Of course, it should look something like this: State / Network / Interface / en1 / IPv4, depending on the interface. With this, I can get an array with ip and netmask. On my Macbook, these arrays contain only one ip and netmask respectively. I suppose this might be different for other Macs, I should check this out. For my test, I just took the first (and only) element in the array, but some kind of size check should be implemented there.
NSString *interfaceState = [NSString stringWithFormat:@"State:/Network/Interface/%@/IPv4", primaryInterface]; CFPropertyListRef ipv4 = SCDynamicStoreCopyValue (storeRef, (CFStringRef)interfaceState); CFRelease(storeRef); NSString *ip = [(__bridge NSDictionary *)ipv4 valueForKey:@"Addresses"][0]; NSString *netmask = [(__bridge NSDictionary *)ipv4 valueForKey:@"SubnetMasks"][0]; CFRelease(ipv4);
It's easy to test, so it's a little rough around the edges. You will need to look for accounts, etc. This was written only to understand how this can be done.