daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Mar 8th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct ifaddrs *address = NULL;
  2.     struct ifaddrs *temp = NULL;
  3.     if (0 != getifaddrs(&address)) {
  4.         NSLog(@"getifaddrs error = %s",strerror(errno));
  5.         return;
  6.     }
  7.     temp = address;
  8.     while (temp->ifa_next != NULL) {
  9.         NSString *if_name = [NSString stringWithUTF8String:temp->ifa_name];
  10.         if ([if_name isEqualToString:@"en1"]) {
  11.             struct sockaddr *ifa_addr = temp->ifa_addr;
  12.             if (ifa_addr->sa_family == AF_INET) {
  13.                 struct sockaddr_in *in_address = (struct sockaddr_in *)ifa_addr;
  14.                 char *ip_str;
  15.                 ip_str = inet_ntoa(in_address->sin_addr);
  16.                 ipTF.stringValue = [NSString stringWithFormat:@"%s",ip_str];
  17.             }
  18.         }
  19.         temp = temp->ifa_next;
  20.     }
  21.     freeifaddrs(address);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top