Last active
August 29, 2015 14:27
-
-
Save Na0ki/9e588834360297e71e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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