标签:style blog color os io div ar amp
#include <arpa/inet.h> #include <net/if.h> #include <ifaddrs.h>
- (NSString *)localIPAddress { NSString *localIP = nil; struct ifaddrs *addrs; if (getifaddrs(&addrs)==0) { const struct ifaddrs *cursor = addrs; while (cursor != NULL) { if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0) { localIP = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)]; break; } cursor = cursor->ifa_next; } freeifaddrs(addrs); } return localIP; }
标签:style blog color os io div ar amp
原文地址:http://www.cnblogs.com/junzitandandan/p/3871673.html