diff options
author | William Joye <wjoye@cfa.harvard.edu> | 2018-01-23 16:53:51 (GMT) |
---|---|---|
committer | William Joye <wjoye@cfa.harvard.edu> | 2018-01-23 16:53:51 (GMT) |
commit | 51e1f85047b34f095ed69a3024d696997d2667c8 (patch) | |
tree | a8d46838982aa78a35653c10d0b7370d751d6181 /xpa/dns.c | |
parent | 0c198f7902ee997dd8ec3631e8ff1c385257014d (diff) | |
download | blt-51e1f85047b34f095ed69a3024d696997d2667c8.zip blt-51e1f85047b34f095ed69a3024d696997d2667c8.tar.gz blt-51e1f85047b34f095ed69a3024d696997d2667c8.tar.bz2 |
upgrade xpa
Diffstat (limited to 'xpa/dns.c')
-rw-r--r-- | xpa/dns.c | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/xpa/dns.c b/xpa/dns.c deleted file mode 100644 index 68f94bd..0000000 --- a/xpa/dns.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory - */ - -#include <unistd.h> -#include <strings.h> -#include <stdio.h> -#include <stdlib.h> -#include <netdb.h> /* gethostbyname() */ -#include <arpa/inet.h> - -#define SZ_LINE 1024 - -int main(int argc, char **argv) -{ - int i, got; - char host[SZ_LINE]; - struct hostent *hostent; - struct addrinfo *hints=NULL, *addrinfo=NULL; - struct sockaddr_in * p; - - // gethost - if( argc > 1 ) - strcpy(host, argv[1]); - else{ - fprintf(stderr, "calling gethostname() ...\n"); - if( gethostname(host, SZ_LINE) == -1 ){ - perror("gethostname"); - exit(1); - } - else{ - fprintf(stderr, "host name is %s\n", host); - } - } - fprintf(stderr, "\n"); - - fprintf(stderr, "calling getaddrinfo (preferred) ...\n"); - hints = (struct addrinfo *)calloc(1, sizeof(struct addrinfo)); - hints->ai_flags |= AI_CANONNAME; - hints->ai_family = AF_INET; - got = getaddrinfo(host, NULL, hints, &addrinfo); - if( got != 0 ){ - fprintf(stderr, "getaddrinfo rtn: %d %s\n", got, gai_strerror(got)); - perror("getaddrinfo"); - exit(1); - } - else{ - fprintf(stderr, "getaddrinfo() succeeded\n"); - } - fprintf(stderr, "printing ip address via getaddrinfo ...\n"); - if( addrinfo ){ - p = (struct sockaddr_in *)(addrinfo->ai_addr); - fprintf(stderr, "%x (canonical: %s)\n", p->sin_addr.s_addr, addrinfo->ai_canonname); - freeaddrinfo(addrinfo); - if( hints ) free(hints); - } - else{ - fprintf(stderr, "ERROR: can't look up: %s\n", host); - } - fprintf(stderr, "\n"); - - fprintf(stderr, "calling gethostbyname (obsolete) ...\n"); - if( !(hostent = gethostbyname(host)) ){ - perror("gethostbyname"); - exit(1); - } - else{ - fprintf(stderr, "gethostbyname() succeeded\n"); - } - fprintf(stderr, "printing ip address(es) via gethostbyname ...\n"); - if( hostent ){ - for(i=0; hostent->h_addr_list[i]; i++){ - fprintf(stderr, "%x\n", *(int *)hostent->h_addr_list[i]); - } - } - else{ - fprintf(stderr, "ERROR: can't look up: %s\n", host); - } - fprintf(stderr, "\n"); - - return(0); -} |