diff options
author | Werner Koch <wk@gnupg.org> | 2015-10-24 16:27:47 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2015-10-25 16:47:11 +0100 |
commit | 816505958ac4308ee0dfe787d1b706982428b6cc (patch) | |
tree | 5e30e1463c53d988ba5b698d8d179628b5a5401d /dirmngr/t-dns-stuff.c | |
parent | gpg: Provide an interface to patch TOFU updates. (diff) | |
download | gnupg2-816505958ac4308ee0dfe787d1b706982428b6cc.tar.xz gnupg2-816505958ac4308ee0dfe787d1b706982428b6cc.zip |
dirmngr: Implement a getnameinfo wrapper.
* dirmngr/dns-stuff.h (DNS_NUMERICHOST): New.
(DNS_WITHBRACKET): New.
* dirmngr/dns-stuff.c (resolve_name_standard): Factor code out to...
(map_eai_to_gpg_error): new.
(resolve_addr_standard): New.
(resolve_dns_addr): New.
* dirmngr/ks-engine-hkp.c (is_ip_address): Move to ...
* dirmngr/dns-stuff.c (is_ip_address): here. Add support for non
bracketed v6 addresses.
* dirmngr/t-dns-stuff.c: Remove header netdb.h.
(main): Add option --bracket. Use resolve_dns_name instead of
getnameinfo.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'dirmngr/t-dns-stuff.c')
-rw-r--r-- | dirmngr/t-dns-stuff.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/dirmngr/t-dns-stuff.c b/dirmngr/t-dns-stuff.c index 63d4cdd9b..0511f9334 100644 --- a/dirmngr/t-dns-stuff.c +++ b/dirmngr/t-dns-stuff.c @@ -22,9 +22,7 @@ #include <stdio.h> #include <stdlib.h> #include <assert.h> -#ifndef HAVE_W32_SYSTEM -# include <netdb.h> -#endif + #include "util.h" #include "dns-stuff.h" @@ -45,6 +43,7 @@ main (int argc, char **argv) int opt_tor = 0; int opt_cert = 0; int opt_srv = 0; + int opt_bracket = 0; char const *name = NULL; gpgrt_init (); @@ -66,6 +65,7 @@ main (int argc, char **argv) " --verbose print timings etc.\n" " --debug flyswatter\n" " --use-tor use Tor\n" + " --bracket enclose v6 addresses in brackets\n" " --cert lookup a CERT RR\n" " --srv lookup a SRV RR\n" , stdout); @@ -87,6 +87,11 @@ main (int argc, char **argv) opt_tor = 1; argc--; argv++; } + else if (!strcmp (*argv, "--bracket")) + { + opt_bracket = 1; + argc--; argv++; + } else if (!strcmp (*argv, "--cert")) { any_options = opt_cert = 1; @@ -194,8 +199,7 @@ main (int argc, char **argv) { char *cname; dns_addrinfo_t aibuf, ai; - int ret; - char hostbuf[1025]; + char *host; printf ("Lookup on '%s'\n", name); @@ -216,14 +220,30 @@ main (int argc, char **argv) ai->family == AF_INET? "inet4" : "? ", ai->socktype, ai->protocol); - ret = getnameinfo (ai->addr, ai->addrlen, - hostbuf, sizeof hostbuf, - NULL, 0, - NI_NUMERICHOST); - if (ret) - printf ("[getnameinfo failed: %s]\n", gai_strerror (ret)); + err = resolve_dns_addr (ai->addr, ai->addrlen, + (DNS_NUMERICHOST + | (opt_bracket? DNS_WITHBRACKET:0)), + &host); + if (err) + printf ("[getnameinfo failed: %s]", gpg_strerror (err)); + else + { + printf ("%s", host); + xfree (host); + } + + err = resolve_dns_addr (ai->addr, ai->addrlen, + (opt_bracket? DNS_WITHBRACKET:0), + &host); + if (err) + printf ("[getnameinfo failed (2): %s]", gpg_strerror (err)); else - printf ("%s\n", hostbuf); + { + if (!is_ip_address (host)) + printf (" (%s)", host); + xfree (host); + } + putchar ('\n'); } xfree (cname); free_dns_addrinfo (aibuf); |