Skip to content

Instantly share code, notes, and snippets.

@Na0ki
Last active August 29, 2015 14:27
Show Gist options
  • Save Na0ki/9e588834360297e71e7c to your computer and use it in GitHub Desktop.
Save Na0ki/9e588834360297e71e7c to your computer and use it in GitHub Desktop.
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <net/if.h>
@implementation WifiUtils
- (BOOL) checkIsWifi {
struct ifaddrs *addresses;
struct ifaddrs *cursor;
BOOL available = NO;
if (getifaddrs(&addresses) != 0) {
return NO;
}
cursor = addresses;
while (cursor != NULL) {
// ループバックアドレスを無視
if (cursor -> ifa_addr -> sa_family == AF_INET) {
if (!(cursor -> ifa_flags & IFF_LOOPBACK)) {
// Wifiアダプターのチェック
if (strcmp(cursor -> ifa_name, "en0") == 0) {
available = YES;
break;
}
}
}
cursor = cursor -> ifa_next;
}
freeifaddrs(addresses);
return available;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment