aboutsummaryrefslogtreecommitdiffstats
path: root/hostnames.c
diff options
context:
space:
mode:
authorEliteTK <tomasz.kramkowski@gmail.com>2014-07-10 22:35:35 +0100
committerEliteTK <tomasz.kramkowski@gmail.com>2014-07-10 22:35:35 +0100
commita8609ccd901b1942e862c14205026d841e640add (patch)
tree5eaf1d04d454bc45acfdf4c698b2860b91f48a00 /hostnames.c
parent922fe2f68c39a765896d274356c7c9dc4fb9cd73 (diff)
downloadc-stuff-a8609ccd901b1942e862c14205026d841e640add.tar.gz
c-stuff-a8609ccd901b1942e862c14205026d841e640add.tar.xz
c-stuff-a8609ccd901b1942e862c14205026d841e640add.zip
More stuff.
Diffstat (limited to 'hostnames.c')
-rw-r--r--hostnames.c27
1 files changed, 27 insertions, 0 deletions
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 <stdio.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+
+int main(int argc, char **argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <domain-name>\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;
+}