Created
March 5, 2020 00:34
-
-
Save kunigami/aa7ff866749353ebdaf69d49c5c4a660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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