Last active
December 12, 2015 12:29
-
-
Save notxarb/4772561 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
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netdb.h> | |
#include <stdio.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) { | |
const char *hostname = argv[1]; | |
const char *service = argv[2]; | |
struct addrinfo hints; | |
struct addrinfo *res; | |
memset(&hints, 0, sizeof(hints)); | |
hints.ai_family = AF_INET6; | |
hints.ai_socktype = SOCK_STREAM; | |
hints.ai_flags = AI_ADDRCONFIG; | |
int result = getaddrinfo( hostname, | |
service, | |
&hints, | |
&res); | |
printf("result: %d\n", result); | |
printf("ai_flags: %d\n", res->ai_flags); | |
printf("ai_family: %d\n", res->ai_family); | |
printf("ai_socktype: %d\n", res->ai_socktype); | |
printf("ai_protocol: %d\n", res->ai_protocol); | |
printf("Cononical Name: %s\n", res->ai_canonname); | |
printf("Error?: %s\n", gai_strerror(result)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment