From a8609ccd901b1942e862c14205026d841e640add Mon Sep 17 00:00:00 2001 From: EliteTK Date: Thu, 10 Jul 2014 22:35:35 +0100 Subject: More stuff. --- hostnames.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 hostnames.c (limited to 'hostnames.c') diff --git a/hostnames.c b/hostnames.c new file mode 100644 index 0000000..33729e0 --- /dev/null +++ b/hostnames.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + struct hostent* he; + + he = gethostbyname(argv[1]); + + if (!he) { + fputs("Error, could not resolve.\n", stderr); + exit(1); + } + + char str[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, he->h_addr, str, INET_ADDRSTRLEN); + + printf("%s\n", str); + return 0; +} -- cgit v1.2.3-54-g00ecf