diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 01:46:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-06 01:46:30 +0000 |
commit | b5896ba9f6047e7031e2bdee0622d543e11a6734 (patch) | |
tree | fd7b460593a2fee1be579bec5697e6d887ea3421 /auxiliary/name-addr-test/gethostbyaddr.c | |
parent | Initial commit. (diff) | |
download | postfix-b5896ba9f6047e7031e2bdee0622d543e11a6734.tar.xz postfix-b5896ba9f6047e7031e2bdee0622d543e11a6734.zip |
Adding upstream version 3.4.23.upstream/3.4.23upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | auxiliary/name-addr-test/gethostbyaddr.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/auxiliary/name-addr-test/gethostbyaddr.c b/auxiliary/name-addr-test/gethostbyaddr.c new file mode 100644 index 0000000..e58db9e --- /dev/null +++ b/auxiliary/name-addr-test/gethostbyaddr.c @@ -0,0 +1,46 @@ + /* + * gethostbyaddr tester. compile with: + * + * cc -o gethostbyaddr gethostbyaddr.c (SunOS 4.x) + * + * cc -o gethostbyaddr gethostbyaddr.c -lnsl (SunOS 5.x) + * + * run as: gethostbyaddr address + * + * 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; + long addr; + + if (argc != 2) { + fprintf(stderr, "usage: %s i.p.addres\n", argv[0]); + exit(1); + } + addr = inet_addr(argv[1]); + if (hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) { + 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); + } + fprintf(stderr, "host %s not found\n", argv[1]); + exit(1); +} |