Skip to content

Instantly share code, notes, and snippets.

@notxarb
Last active December 12, 2015 12:29
Show Gist options
  • Save notxarb/4772561 to your computer and use it in GitHub Desktop.
Save notxarb/4772561 to your computer and use it in GitHub Desktop.
#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