From a3b571996ea5cb0227b36a20f3fc0986f7ab1b7d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 5 Dec 2004 17:25:48 +0000 Subject: move nss-mdns/* to trunk/ git-svn-id: file:///home/lennart/svn/public/nss-mdns/trunk@49 0ee8848e-81ea-0310-a63a-f631d1a40d77 --- nsstest.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 nsstest.c (limited to 'nsstest.c') diff --git a/nsstest.c b/nsstest.c new file mode 100644 index 0000000..d4f1c4c --- /dev/null +++ b/nsstest.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + struct hostent *he; + in_addr_t **a; + char *arg= argc > 1 ? argv[1] : "whiskey.local"; + uint8_t t[256]; + + if (inet_pton(AF_INET, arg, &t) > 0) + he = gethostbyaddr(t, 4, AF_INET); + else if (inet_pton(AF_INET6, arg, &t) > 0) + he = gethostbyaddr(t, 16, AF_INET6); + else + he = gethostbyname(arg); + + if (!he) { + fprintf(stderr, "lookup failed\n"); + return 1; + } + + fprintf(stderr, "official name: %s\n", he->h_name); + + if (!he->h_aliases || !he->h_aliases[0]) + fprintf(stderr, "no aliases\n"); + else { + char **h; + fprintf(stderr, "aliases:"); + for (h = he->h_aliases; *h; h++) + fprintf(stderr, " %s", *h); + fprintf(stderr, "\n"); + } + + fprintf(stderr, "addr type: %s\n", he->h_addrtype == AF_INET ? "inet" : (he->h_addrtype == AF_INET6 ? "inet6" : NULL)); + fprintf(stderr, "addr length: %i\n", he->h_length); + + fprintf(stderr, "addresses:"); + for (a = (in_addr_t**) he->h_addr_list; *a; a++) { + char t[256]; + fprintf(stderr, " %s", inet_ntop(he->h_addrtype, *a, t, sizeof(t))); + } + fprintf(stderr, "\n"); + + return 0; +} -- cgit