int status; | |
struct addrinfo hints; | |
struct addrinfo *servinfo; // will point to the results | |
memset(&hints, 0, sizeof hints); // make sure the struct is empty | |
hints.ai_family = AF_INET6; // IPv6 | |
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets | |
hints.ai_flags = AI_PASSIVE; // fill in my IP for me | |
getaddrinfo("www.google.com", "https", &hints, &servinfo); | |
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)servinfo->ai_addr; | |
void *addr = &(ipv6->sin6_addr); | |
char ipstr[INET6_ADDRSTRLEN]; | |
inet_ntop(servinfo->ai_family, addr, ipstr, sizeof ipstr); | |
printf("IP: %s\n", ipstr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment