5359edc160de518d8e43fdd3448365c15b912c3c galt Mon Jul 22 11:48:10 2019 -0700 Added ipv6 support. Listening processes us hybrid dual stack feature of OS to simplify implementation and use a single listening socket. Works with both TCP and UDP. Parasol working. geoIp also updated and ready for IPv6. Should be invisible to most users, while providing connections via ipv6 where available. Supports both ipv4 and ipv6. diff --git src/utils/dnsInfo/dnsInfo.c src/utils/dnsInfo/dnsInfo.c index 34949f9..28233a8 100644 --- src/utils/dnsInfo/dnsInfo.c +++ src/utils/dnsInfo/dnsInfo.c @@ -1,76 +1,77 @@ /* dnsInfo - Get info from DNS about a machine. */ /* Copyright (C) 2011 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include #include #include #include #include "linefile.h" #include "hash.h" #include "options.h" void usage() /* Explain usage and exit. */ { errAbort( "dnsInfo - Get info from DNS about a machine\n" "usage:\n" " dnsInfo machine\n" ); } void dnsInfo(char *machine) /* dnsInfo - Get info from DNS about a machine. */ { -struct hostent *h; -char **aliases, **addresses; -char str[INET6_ADDRSTRLEN]; + + +struct addrinfo hints; +ZeroVar(&hints); +hints.ai_flags = AI_NUMERICSERV; +hints.ai_family = AF_UNSPEC; +hints.ai_socktype = SOCK_STREAM; // Get apparent dupes without this. + +struct addrinfo *ai, *p = NULL; if (sameString(machine, "localhost")) { struct utsname myname; if (uname(&myname) < 0) errnoAbort("Couldn't uname."); printf("localhost: %s\n", myname.nodename); machine = myname.nodename; { char buf[256]; if (getdomainname(buf, sizeof(buf)) < 0) errnoAbort("getdomainname error"); printf("domain name: %s\n", buf); } } -if ((h = gethostbyname(machine)) == NULL) - errAbort("Couldn't gethostbyname: %s", hstrerror(h_errno)); -printf("official hostname: %s\n", h->h_name); -for (aliases = h->h_aliases; *aliases != NULL; ++aliases) - printf("\talias: %s\n", *aliases); -switch (h->h_addrtype) - { - case AF_INET: - case AF_INET6: - addresses = h->h_addr_list; - for (addresses = h->h_addr_list; *addresses != NULL; ++addresses) + +/********************************************************************/ +/* Get the address information for the server using getaddrinfo(). */ +/********************************************************************/ +int rc = getaddrinfo(machine, NULL, &hints, &ai); +if (rc != 0) + errAbort("getaddrinfo() failed"); + +for (p = ai; p; p = p->ai_next) { - printf("\taddress: %s\n", - inet_ntop(h->h_addrtype, *addresses, str, sizeof(str))); - } - break; - default: - errAbort("unknown address type %d", (int)h->h_addrtype); - break; + char host[256]; + getnameinfo(p->ai_addr, p->ai_addrlen, host, sizeof (host), NULL, 0, NI_NUMERICHOST); + puts(host); } +freeaddrinfo(ai); } int main(int argc, char *argv[]) /* Process command line. */ { optionHash(&argc, argv); if (argc != 2) usage(); dnsInfo(argv[1]); return 0; }