Guest User

Untitled

a guest
Mar 8th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  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);
Add Comment
Please, Sign In to add comment