validation - Is this an IP address? -


i using nsnetservice class resolve ip addresses using mdns discovery. 2 results:

something looks this:

ae60::x:1cdf:x:212 

(where x value similar others)

and classic ip address, like: 10.x.x.2

is first result ip address?

this code using retrieve address:

char addressbuffer[inet6_addrstrlen];  (nsdata *data in service.addresses) {     memset(addressbuffer, 0, inet6_addrstrlen);      typedef union {         struct sockaddr sa;         struct sockaddr_in ipv4;         struct sockaddr_in6 ipv6;     } ip_socket_address;      ip_socket_address *socketaddress = (ip_socket_address *)[data bytes];      if (socketaddress && (socketaddress->sa.sa_family == af_inet || socketaddress->sa.sa_family == af_inet6))     {         const char *addressstr = inet_ntop(                                            socketaddress->sa.sa_family,                                            (socketaddress->sa.sa_family == af_inet ? (void *)&(socketaddress->ipv4.sin_addr) : (void *)&(socketaddress->ipv6.sin6_addr)),                                            addressbuffer,                                            sizeof(addressbuffer));          int port = ntohs(socketaddress->sa.sa_family == af_inet ? socketaddress->ipv4.sin_port : socketaddress->ipv6.sin6_port);          if (addressstr && port)         {             nsstring * address = [nsstring stringwithformat:@"%s", addressstr];             nslog(@"found service @ %s:%d", addressstr, port);         }     } } 

you've got ipv6 ip address 2001:4860:4860::8888 (the address of 1 of google's dns servers).


Comments