From 8bccbf477878fd99baa96e11db9db99aaf1e8d91 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 21 Oct 2015 17:55:56 +0200 Subject: dirmngr: Implement a getaddrinfo wrapper. * dirmngr/dns-stuff.h: Include some header files. (dns_addinfo_t, dns_addrinfo_s): New. * dirmngr/dns-stuff.c: Always include DNS related headers. (free_dns_addrinfo): New. (resolve_name_standard): New. (resolve_dns_name): New. * dirmngr/t-dns-stuff.c: Include netdb.h. (main): Keep old default mode with no args but else print outout of resolve_dns_name. Revamp option parser. -- This wrapper allows us to switch to ADNS and thus Tor for standard name resultion. Signed-off-by: Werner Koch --- dirmngr/dns-stuff.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'dirmngr/dns-stuff.h') diff --git a/dirmngr/dns-stuff.h b/dirmngr/dns-stuff.h index aea0e69f6..090e79b4d 100644 --- a/dirmngr/dns-stuff.h +++ b/dirmngr/dns-stuff.h @@ -30,6 +30,16 @@ #ifndef GNUPG_DIRMNGR_DNS_STUFF_H #define GNUPG_DIRMNGR_DNS_STUFF_H +#ifdef HAVE_W32_SYSTEM +# ifdef HAVE_WINSOCK2_H +# include +# endif +# include +#else +# include +# include +#endif + #define DNS_CERTTYPE_ANY 0 /* Internal catch all type. */ /* Certificate types according to RFC-4398: */ @@ -48,10 +58,31 @@ #define DNS_CERTTYPE_RRBASE 1024 /* Base of special constants. */ #define DNS_CERTTYPE_RR61 (DNS_CERTTYPE_RRBASE + 61) +struct dns_addrinfo_s; +typedef struct dns_addrinfo_s *dns_addrinfo_t; +struct dns_addrinfo_s +{ + dns_addrinfo_t next; + int family; + int socktype; + int protocol; + int addrlen; + struct sockaddr addr[1]; +}; + + + /* Calling this function switches the DNS code into Tor mode if possibe. Return 0 on success. */ gpg_error_t enable_dns_tormode (void); +void free_dns_addrinfo (dns_addrinfo_t ai); + +/* Provide function similar to getaddrinfo. */ +gpg_error_t resolve_dns_name (const char *name, unsigned short port, + int want_family, int want_socktype, + dns_addrinfo_t *r_dai, char **r_canonname); + /* Return a CERT record or an arbitray RR. */ gpg_error_t get_dns_cert (const char *name, int want_certtype, void **r_key, size_t *r_keylen, -- cgit v1.2.3