Created
December 9, 2016 10:29
-
-
Save ryo/db49650a1190be9f0c7f5727df2eee35 to your computer and use it in GitHub Desktop.
gethostbyname2 test
This file contains hidden or 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 <stdio.h> | |
#include <sys/socket.h> | |
#include <netdb.h> | |
int | |
main(int argc, char *argv[]) | |
{ | |
static struct hostent h_ent; | |
static char h_buf[16384]; | |
struct hostent *hent; | |
int herr = 0; | |
if (argc != 2) { | |
fprintf(stderr, "usage: gethostbyname2_inet6 <host>\n"); | |
return 1; | |
} | |
hent = gethostbyname2(argv[1], AF_INET6); | |
printf("getostbyname2: hostent=%p, error(h_errno)=%d\n", hent, h_errno); | |
#ifdef __NetBSD__ | |
struct hostent *gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, int *); | |
hent = gethostbyname2_r(argv[1], AF_INET6, &h_ent, h_buf, sizeof(h_buf), &herr); | |
printf("gethostbyname2_r: hostent=%p, error(locally)=%d\n", hent, herr); | |
#elif defined(__FreeBSD__) || defined(__linux__) | |
int rc = gethostbyname2_r(argv[1], AF_INET6, &h_ent, h_buf, sizeof(h_buf), &hent, &herr); | |
printf("gethostbyname2_r: hostent=%p, error(locally)=%d, return=%d\n", hent, herr, rc); | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment