I found the following (working) code useful to generate all of the potential broadcast addresses for all of the networks your computer is connected to:
+ (NSDictionary *)allNetworks {
NSMutableDictionary *networkStates = [NSMutableDictionary new];
SCDynamicStoreRef storeRef = SCDynamicStoreCreate(NULL, (CFStringRef)@"FindCurrentInterfaceIpMac", NULL, NULL);
if (storeRef) {
NSDictionary *interfaceInfo = CFBridgingRelease(SCDynamicStoreCopyValue(storeRef, CFSTR("State:/Network/Interface")));
NSArray *primaryInterfaces = interfaceInfo[@"Interfaces"];
for (NSString* interfaceName in primaryInterfaces) {
NSString *interfaceStateKey = [NSString stringWithFormat:@"State:/Network/Interface/%@/IPv4", interfaceName];
NSDictionary *ipv4State = CFBridgingRelease(SCDynamicStoreCopyValue(storeRef, (__bridge CFStringRef)interfaceStateKey));
if (ipv4State != nil) {
networkStates[interfaceName] = ipv4State;
}
}
CFRelease(storeRef);
}
return networkStates;
}
The returned dictionary will have the network interface names as keys, and the values will be dictionaries that have the keys @"Addresses", @"BroadcastAddresses", and @"SubnetMasks" and arrays of strings as the values. To add this to your code, you'll need to include
#import <SystemConfiguration/SCDynamicStore.h>
and link against SystemConfiguration.framework.