1

I am using NSNetService class to resolve IP addresses using MDNS discovery. I get two results:

Something that looks like this:

ae60::x:1cdf:x:212

(where x is another value similar to the others)

And the classic ip address, like: 10.x.x.2

Is the first result also an IP address?

This is the code I am using to retrieve the address:

char addressBuffer[INET6_ADDRSTRLEN];

for (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 at %s:%d", addressStr, port);
        }
    }
}
mm24
  • 9,280
  • 12
  • 75
  • 170
  • 1
    `ae60::x:1cdf:x:212`is an IPv6 adress, while `10.2.x.x.x` is an IPv4 adress. The first one become more popular, because the adress pool of given IPv4 adresses is almost empty. – Reporter May 08 '15 at 11:05

3 Answers3

2

You've got an IPv6 IP address like 2001:4860:4860::8888 (the address of one of google's DNS servers).

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251
2

Yes, the string formatted like ae60::x:1cdf:x:212 is an IPv6 address.

Alfred Rossi
  • 1,942
  • 15
  • 19
1

Short answer: YES

Long answer: This is an IPv6 Address, the new kind of IP Address. The shorter Version (IPv4, for example 168.192.1.1) is the old one, but a new format was needed which supports a lot more combinations.

http://en.wikipedia.org/wiki/IPv6

Florian Moser
  • 2,583
  • 1
  • 30
  • 40