#include #include #include #include #include #include #include #include #include int main() { struct addrinfo req; void *ptr; memset(&req, 0, sizeof(req)); struct addrinfo *res, *i; int ret = 0; char buf[NI_MAXHOST]; req.ai_family = AF_INET6; req.ai_socktype = SOCK_DGRAM; ret = getaddrinfo("google.com", NULL, &req, &res); if (ret == 0) { while (res) { memset(buf, 0, NI_MAXHOST); ptr = &((struct sockaddr_in6*)res->ai_addr)->sin6_addr; inet_ntop(AF_INET6, ptr, buf, NI_MAXHOST); printf("%s\n", buf); res = res->ai_next; } } else { printf("invalid %s\n", gai_strerror(ret)); } }