Last active
December 27, 2015 13:19
-
-
Save colmmacc/7332057 to your computer and use it in GitHub Desktop.
Trivial test program to investigate multiple addresses returned by gethostbyname. To run do: gcc -o tester tester.c ; ./tester beta.allcosts.net
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/socket.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
#include <netdb.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
int main(int argc, char ** argv) | |
{ | |
int i; | |
struct hostent * answer = gethostbyname(argv[1]); | |
if (!answer) { | |
return 1; | |
} | |
for(i = 0; answer->h_addr_list[i] != NULL; i++) { | |
struct in_addr in; | |
memcpy(&in.s_addr, answer->h_addr_list[i], sizeof(in.s_addr)); | |
printf("%s\n", inet_ntoa(in)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment