diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 19:59:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 19:59:03 +0000 |
commit | a848231ae0f346dc7cc000973fbeb65b0894ee92 (patch) | |
tree | 44b60b367c86723cc78383ef247885d72b388afe /auxiliary/name-addr-test/gethostbyname.c | |
parent | Initial commit. (diff) | |
download | postfix-a848231ae0f346dc7cc000973fbeb65b0894ee92.tar.xz postfix-a848231ae0f346dc7cc000973fbeb65b0894ee92.zip |
Adding upstream version 3.8.5.upstream/3.8.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | auxiliary/name-addr-test/gethostbyname.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/auxiliary/name-addr-test/gethostbyname.c b/auxiliary/name-addr-test/gethostbyname.c new file mode 100644 index 0000000..d8079dd --- /dev/null +++ b/auxiliary/name-addr-test/gethostbyname.c @@ -0,0 +1,44 @@ + /* + * gethostbyname tester. compile with: + * + * cc -o gethostbyname gethostbyname.c (SunOS 4.x) + * + * cc -o gethostbyname gethostbyname.c -lnsl (SunOS 5.x) + * + * run as: gethostbyname hostname + * + * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. + */ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <stdio.h> + +main(argc, argv) +int argc; +char **argv; +{ + struct hostent *hp; + + if (argc != 2) { + fprintf(stderr, "usage: %s hostname\n", argv[0]); + exit(1); + } + if (hp = gethostbyname(argv[1])) { + printf("Hostname:\t%s\n", hp->h_name); + printf("Aliases:\t"); + while (hp->h_aliases[0]) + printf("%s ", *hp->h_aliases++); + printf("\n"); + printf("Addresses:\t"); + while (hp->h_addr_list[0]) + printf("%s ", inet_ntoa(*(struct in_addr *) * hp->h_addr_list++)); + printf("\n"); + exit(0); + } else { + fprintf(stderr, "host %s not found\n", argv[1]); + exit(1); + } +} |