#include #include #include #include #include #include int main(int argc, char **argv) { struct addrinfo hints, *result, *ai; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_socktype = SOCK_STREAM; hints.ai_flags |= AI_PASSIVE; hints.ai_flags |= AI_ADDRCONFIG; if (getaddrinfo(NULL, argv[1], &hints, &result)) { printf("failed to get addresses\n"); exit(EXIT_FAILURE); } for (ai = result; ai != NULL; ai = ai->ai_next) { if (ai->ai_family == AF_INET) printf("this is an IPv4 result\n"); else if(ai->ai_family == AF_INET6) printf("this is an IPv6 result\n"); else printf("eww what's this?\n"); } freeaddrinfo(result); }