From 9d3905459e23bca666e0dec0aa3390f05e38950c Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Thu, 24 Dec 2015 14:41:50 +0100 Subject: [PATCH] Miscellaneous fixes to compile on windows Also without warnings. --- Makefile.in | 1 + README.md | 12 +- configure.ac | 102 +-- m4/acx_getaddrinfo.m4 | 81 ++ src/context.c | 170 ++-- src/general.c | 82 +- src/samplewin/Makefile.in | 150 ---- src/samplewin/getdns_query.c | 1524 ---------------------------------- src/stub.c | 18 +- src/test/getdns_query.c | 12 +- src/util/winsock_event.c | 42 +- src/util/winsock_event.h | 26 +- 12 files changed, 301 insertions(+), 1919 deletions(-) create mode 100644 m4/acx_getaddrinfo.m4 delete mode 100644 src/samplewin/Makefile.in delete mode 100644 src/samplewin/getdns_query.c diff --git a/Makefile.in b/Makefile.in index 5f10efca..9e7fb66a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -193,6 +193,7 @@ $(distdir): cp $(srcdir)/install-sh $(distdir) cp $(srcdir)/config.sub $(distdir) cp $(srcdir)/config.guess $(distdir) + cp $(srcdir)/getdns.pc.in $(distdir) cp libtool $(distdir) cp $(srcdir)/ltmain.sh $(distdir) cp $(srcdir)/m4/*.m4 $(distdir)/m4 diff --git a/README.md b/README.md index 8b6143dd..5b9cabd0 100644 --- a/README.md +++ b/README.md @@ -255,20 +255,18 @@ libidn The windows version of getdns currently only is supported in the stub only mode. To configure: - ./configure --enable-use-winsock --enable-stub-only --with-trust-anchor="c:\\\MinGW\\\msys\\\1.0\\\etc\\\unbound\\\getdns-root.key" + ./configure --enable-stub-only --with-trust-anchor="c:\\\MinGW\\\msys\\\1.0\\\etc\\\unbound\\\getdns-root.key" --with-ssl=/c/OpenSSL --with-getdns_query The trust anchor is also installed by unbound on c:\program Files (X86)\unbound\root.key and can be referenced from there or anywhere else that the user chooses to configure it. After configuring, do a 'make' and 'make install' to build getdns for Windows. - There is a sample, getdns_query.exe which can be built in src/samplewin using 'make' - Example test queries: - ./getdns_query.exe -s gmadkat.com A @64.6.64.6 +return_call_debugging (UDP) - ./getdns_query.exe -s gmadkat.com A @64.6.64.6 -T +return_call_debugging (TCP) - ./getdns_query.exe -s gmadkat.com A -l L @185.49.141.37 +return_call_debugging (TLS without authentication) - ./getdns_query.exe -s www.huque.com A +dnssec_return_status +return_call_debugging (DNSSEC) + ./getdns_query.exe -s gmadkat.com A @64.6.64.6 +return_call_reporting (UDP) + ./getdns_query.exe -s gmadkat.com A @64.6.64.6 -T +return_call_reporting (TCP) + ./getdns_query.exe -s gmadkat.com A -l L @185.49.141.37 +return_call_reporting (TLS without authentication) + ./getdns_query.exe -s www.huque.com A +dnssec_return_status +return_call_reporting (DNSSEC) Contributors ============ diff --git a/configure.ac b/configure.ac index 43696eac..417c3361 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,7 @@ AC_PREREQ([2.56]) AC_CONFIG_MACRO_DIRS([m4]) sinclude(./m4/acx_openssl.m4) +sinclude(./m4/acx_getaddrinfo.m4) sinclude(./m4/ax_check_compile_flag.m4) sinclude(./m4/pkg.m4) @@ -444,56 +445,53 @@ case "$enable_stub_only" in esac # search to set include and library paths right -# find libidn -my_with_libidn=1 - -AC_MSG_NOTICE([Checking if building on Windows]) -AC_ARG_ENABLE(use-winsock, AC_HELP_STRING([--enable-use-winsock], [Enable building for Microsoft Windows using mingw])) -case "$enable_use_winsock" in - yes) - AC_MSG_NOTICE([ Building on Windows ... YES! ]) - AC_DEFINE_UNQUOTED([USE_WINSOCK], [1], [Define this to enable Windows build.]) - AC_DEFINE_UNQUOTED([GETDNS_ON_WINDOWS], [1], [Define this to enable Windows build.]) - AC_DEFINE_UNQUOTED([HAVE_WINSOCK2_H], [1], [Define this to enable Windows build.]) - AC_DEFINE_UNQUOTED([HAVE_WS2TCPIP_H], [1], [Define this to enable Windows build.]) - AC_DEFINE_UNQUOTED([STUB_NATIVE_DNSSEC], [1], [Define this to enable Windows build.]) - my_with_libunbound=0 - my_with_libidn=0 - ;; - no|*) - AC_MSG_NOTICE([ Building on Windows ... YES! ]) - ;; -esac - -AC_ARG_WITH(libidn, AS_HELP_STRING([--with-libidn=pathname], - [path to libidn (default: search /usr/local ..)]), - [], [withval="yes"]) -if test x_$withval = x_yes; then - for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do - if test -f "$dir/include/idna.h"; then - CFLAGS="$CFLAGS -I$dir/include" - LDFLAGS="$LDFLAGS -L$dir/lib" - AC_MSG_NOTICE([Found libidn in $dir]) - break - fi - if test -f "$dir/include/idn/idna.h"; then - CFLAGS="$CFLAGS -I$dir/include/idn" - LDFLAGS="$LDFLAGS -L$dir/lib" - AC_MSG_NOTICE([Found libidn in $dir]) - break - fi - done - if test -f "/usr/include/idn/idna.h"; then - CFLAGS="$CFLAGS -I/usr/include/idn" - #LDFLAGS="$LDFLAGS -L/usr/lib" - AC_MSG_NOTICE([Found libidn in /usr]) - fi +# find libidn (no libidn on windows though) +AC_CHECK_HEADERS([windows.h winsock.h stdio.h winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT]) +ACX_CHECK_GETADDRINFO_WITH_INCLUDES +if test "$USE_WINSOCK" = 1; then + AC_MSG_NOTICE([ Building on Windows ... YES! ]) + AC_DEFINE_UNQUOTED([GETDNS_ON_WINDOWS], [1], [Define this to enable Windows build.]) + AC_DEFINE_UNQUOTED([STUB_NATIVE_DNSSEC], [1]) + LIBS="$LIBS -lgdi32 -liphlpapi" + my_with_libunbound=0 + my_with_libidn=0 else - if test x_$withval != x_no; then - CFLAGS="$CFLAGS -I$withval/include" - LDFLAGS="$LDFLAGS -L$withval/lib" + my_with_libidn=1 +fi + + +if test $my_with_libidn = 1 +then + AC_ARG_WITH(libidn, AS_HELP_STRING([--with-libidn=pathname], + [path to libidn (default: search /usr/local ..)]), + [], [withval="yes"]) + if test x_$withval = x_yes; then + for dir in /usr/local /opt/local /usr/pkg /usr/sfw; do + if test -f "$dir/include/idna.h"; then + CFLAGS="$CFLAGS -I$dir/include" + LDFLAGS="$LDFLAGS -L$dir/lib" + AC_MSG_NOTICE([Found libidn in $dir]) + break + fi + if test -f "$dir/include/idn/idna.h"; then + CFLAGS="$CFLAGS -I$dir/include/idn" + LDFLAGS="$LDFLAGS -L$dir/lib" + AC_MSG_NOTICE([Found libidn in $dir]) + break + fi + done + if test -f "/usr/include/idn/idna.h"; then + CFLAGS="$CFLAGS -I/usr/include/idn" + #LDFLAGS="$LDFLAGS -L/usr/lib" + AC_MSG_NOTICE([Found libidn in /usr]) + fi else - my_with_libidn=0 + if test x_$withval != x_no; then + CFLAGS="$CFLAGS -I$withval/include" + LDFLAGS="$LDFLAGS -L$withval/lib" + else + my_with_libidn=0 + fi fi fi @@ -1105,6 +1103,14 @@ void SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*); unsigned char *SHA512(void* data, unsigned int data_len, unsigned char *digest); #endif /* COMPAT_SHA512 */ +#ifndef HAVE_INET_PTON +int inet_pton(int af, const char* src, void* dst); +#endif /* HAVE_INET_PTON */ + +#ifndef HAVE_INET_NTOP +const char *inet_ntop(int af, const void *src, char *dst, size_t size); +#endif + #ifdef __cplusplus } #endif diff --git a/m4/acx_getaddrinfo.m4 b/m4/acx_getaddrinfo.m4 new file mode 100644 index 00000000..e88e1ddd --- /dev/null +++ b/m4/acx_getaddrinfo.m4 @@ -0,0 +1,81 @@ +# Taken from acx_nlnetlabs.m4 - common macros for configure checks +# Copyright 2009, Wouter Wijngaards, NLnet Labs. +# BSD licensed. +# + +dnl Check getaddrinfo. +dnl Works on linux, solaris, bsd and windows(links winsock). +dnl defines HAVE_GETADDRINFO, USE_WINSOCK. +AC_DEFUN([ACX_CHECK_GETADDRINFO_WITH_INCLUDES], +[AC_REQUIRE([AC_PROG_CC]) +AC_MSG_CHECKING(for getaddrinfo) +ac_cv_func_getaddrinfo=no +AC_LINK_IFELSE( +[AC_LANG_SOURCE([[ +#ifdef __cplusplus +extern "C" +{ +#endif +char* getaddrinfo(); +char* (*f) () = getaddrinfo; +#ifdef __cplusplus +} +#endif +int main() { + ; + return 0; +} +]])], +dnl this case on linux, solaris, bsd +[ac_cv_func_getaddrinfo="yes" +dnl see if on windows +if test "$ac_cv_header_windows_h" = "yes"; then + AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) + USE_WINSOCK="1" + LIBS="$LIBS -lws2_32" +fi +], +dnl no quick getaddrinfo, try mingw32 and winsock2 library. +ORIGLIBS="$LIBS" +LIBS="$LIBS -lws2_32" +AC_LINK_IFELSE( +[AC_LANG_PROGRAM( +[ +#define _WIN32_WINNT 0x0501 +#ifdef HAVE_WINDOWS_H +#include +#endif +#ifdef HAVE_WINSOCK_H +#include +#endif +#ifdef HAVE_WINSOCK2_H +#include +#endif +#include +#ifdef HAVE_WS2TCPIP_H +#include +#endif +], +[ + (void)getaddrinfo(NULL, NULL, NULL, NULL); +] +)], +[ +ac_cv_func_getaddrinfo="yes" +dnl already: LIBS="$LIBS -lws2_32" +AC_DEFINE(USE_WINSOCK, 1, [Whether the windows socket API is used]) +USE_WINSOCK="1" +], +[ +ac_cv_func_getaddrinfo="no" +LIBS="$ORIGLIBS" +]) +) + +AC_MSG_RESULT($ac_cv_func_getaddrinfo) +if test $ac_cv_func_getaddrinfo = yes; then + AC_DEFINE(HAVE_GETADDRINFO, 1, [Whether getaddrinfo is available]) +fi +])dnl Endof AC_CHECK_GETADDRINFO_WITH_INCLUDES + +dnl End of file diff --git a/src/context.c b/src/context.c index 85af776d..89858323 100644 --- a/src/context.c +++ b/src/context.c @@ -106,7 +106,6 @@ getdns_port_str_array[] = { /* Private functions */ static getdns_return_t create_default_namespaces(struct getdns_context *context); static getdns_return_t create_default_dns_transports(struct getdns_context *context); -static getdns_return_t set_os_defaults(struct getdns_context *); static int transaction_id_cmp(const void *, const void *); static void dispatch_updated(struct getdns_context *, uint16_t); static void cancel_dns_req(getdns_dns_req *); @@ -705,6 +704,89 @@ upstream_init(getdns_upstream *upstream, net_req_query_id_cmp); } +#ifdef USE_WINSOCK +static getdns_return_t +set_os_defaults_windows(struct getdns_context *context) +{ + char domain[1024]; + size_t upstreams_limit = 10, length; + struct getdns_bindata bindata; + struct addrinfo hints; + struct addrinfo *result; + getdns_upstream *upstream; + int s; + + if (context->fchg_resolvconf == NULL) { + context->fchg_resolvconf = + GETDNS_MALLOC(context->my_mf, struct filechg); + if (context->fchg_resolvconf == NULL) + return GETDNS_RETURN_MEMORY_ERROR; + context->fchg_resolvconf->fn = "InvalidOnWindows"; + context->fchg_resolvconf->prevstat = NULL; + context->fchg_resolvconf->changes = GETDNS_FCHG_NOCHANGES; + context->fchg_resolvconf->errors = GETDNS_FCHG_NOERROR; + } + _getdns_filechg_check(context, context->fchg_resolvconf); + + context->suffix = getdns_list_create_with_context(context); + context->upstreams = upstreams_create(context, upstreams_limit); + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ + hints.ai_socktype = 0; /* Datagram socket */ + hints.ai_flags = AI_NUMERICHOST; /* No reverse name lookups */ + hints.ai_protocol = 0; /* Any protocol */ + hints.ai_canonname = NULL; + hints.ai_addr = NULL; + hints.ai_next = NULL; + + FIXED_INFO *info; + ULONG buflen = sizeof(*info); + IP_ADDR_STRING *ptr = 0; + + info = (FIXED_INFO *)malloc(sizeof(FIXED_INFO)); + if (info == NULL) + return GETDNS_RETURN_GENERIC_ERROR; + + if (GetNetworkParams(info, &buflen) == ERROR_BUFFER_OVERFLOW) { + free(info); + info = (FIXED_INFO *)malloc(buflen); + if (info == NULL) + return GETDNS_RETURN_GENERIC_ERROR; + } + + if (GetNetworkParams(info, &buflen) == NO_ERROR) { + ptr = info->DnsServerList.Next; + *domain = 0; + while (ptr) { + for (size_t i = 0; i < GETDNS_UPSTREAM_TRANSPORTS; i++) { + char *port_str = getdns_port_str_array[i]; + if ((s = getaddrinfo(ptr->IpAddress.String, port_str, &hints, &result))) + continue; + if (!result) + continue; + + upstream = &context->upstreams-> + upstreams[context->upstreams->count++]; + upstream_init(upstream, context->upstreams, result); + upstream->transport = getdns_upstream_transports[i]; + freeaddrinfo(result); + } + ptr = ptr->Next; + + } + free(info); + } + + (void)getdns_list_get_length(context->suffix, &length); + if (length == 0 && *domain != 0) { + bindata.data = (uint8_t *)domain; + bindata.size = strlen(domain) + 1; + (void)getdns_list_set_bindata(context->suffix, 0, &bindata); + } + return GETDNS_RETURN_GOOD; +} /* set_os_defaults_windows */ +#else static getdns_return_t set_os_defaults(struct getdns_context *context) { @@ -816,92 +898,6 @@ set_os_defaults(struct getdns_context *context) _getdns_list_append_string(context->suffix, domain); return GETDNS_RETURN_GOOD; } /* set_os_defaults */ - -#ifdef USE_WINSOCK -static getdns_return_t -set_os_defaults_windows(struct getdns_context *context) -{ - FILE *in; - char line[1024], domain[1024]; - char *parse, *token, prev_ch; - size_t upstreams_limit = 10, length; - struct getdns_bindata bindata; - struct addrinfo hints; - struct addrinfo *result; - getdns_upstream *upstream; - int s; - - if (context->fchg_resolvconf == NULL) { - context->fchg_resolvconf = - GETDNS_MALLOC(context->my_mf, struct filechg); - if (context->fchg_resolvconf == NULL) - return GETDNS_RETURN_MEMORY_ERROR; - context->fchg_resolvconf->fn = "InvalidOnWindows"; - context->fchg_resolvconf->prevstat = NULL; - context->fchg_resolvconf->changes = GETDNS_FCHG_NOCHANGES; - context->fchg_resolvconf->errors = GETDNS_FCHG_NOERROR; - } - _getdns_filechg_check(context, context->fchg_resolvconf); - - context->suffix = getdns_list_create_with_context(context); - context->upstreams = upstreams_create(context, upstreams_limit); - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ - hints.ai_socktype = 0; /* Datagram socket */ - hints.ai_flags = AI_NUMERICHOST; /* No reverse name lookups */ - hints.ai_protocol = 0; /* Any protocol */ - hints.ai_canonname = NULL; - hints.ai_addr = NULL; - hints.ai_next = NULL; - - FIXED_INFO *info; - ULONG buflen = sizeof(*info); - IP_ADDR_STRING *ptr = 0; - - info = (FIXED_INFO *)malloc(sizeof(FIXED_INFO)); - if (info == NULL) - return GETDNS_RETURN_GENERIC_ERROR; - - if (GetNetworkParams(info, &buflen) == ERROR_BUFFER_OVERFLOW) { - free(info); - info = (FIXED_INFO *)malloc(buflen); - if (info == NULL) - return GETDNS_RETURN_GENERIC_ERROR; - } - - if (GetNetworkParams(info, &buflen) == NO_ERROR) { - int retval = 0; - ptr = info->DnsServerList.Next; - *domain = 0; - while (ptr) { - for (size_t i = 0; i < GETDNS_UPSTREAM_TRANSPORTS; i++) { - char *port_str = getdns_port_str_array[i]; - if ((s = getaddrinfo(ptr->IpAddress.String, port_str, &hints, &result))) - continue; - if (!result) - continue; - - upstream = &context->upstreams-> - upstreams[context->upstreams->count++]; - upstream_init(upstream, context->upstreams, result); - upstream->transport = getdns_upstream_transports[i]; - freeaddrinfo(result); - } - ptr = ptr->Next; - - } - free(info); - } - - (void)getdns_list_get_length(context->suffix, &length); - if (length == 0 && *domain != 0) { - bindata.data = (uint8_t *)domain; - bindata.size = strlen(domain) + 1; - (void)getdns_list_set_bindata(context->suffix, 0, &bindata); - } - return GETDNS_RETURN_GOOD; -} /* set_os_defaults_windows */ #endif /* compare of transaction ids in DESCENDING order diff --git a/src/general.c b/src/general.c index c73a2e9e..9ac63f46 100644 --- a/src/general.c +++ b/src/general.c @@ -346,50 +346,50 @@ _getdns_hostname_loop(getdns_context *context, getdns_eventloop *loop, switch (address_data->size) { case 4: (void)snprintf(name, sizeof(name), - "%hhu.%hhu.%hhu.%hhu.in-addr.arpa.", - ((uint8_t *)address_data->data)[3], - ((uint8_t *)address_data->data)[2], - ((uint8_t *)address_data->data)[1], - ((uint8_t *)address_data->data)[0]); + "%d.%d.%d.%d.in-addr.arpa.", + (int)((uint8_t *)address_data->data)[3], + (int)((uint8_t *)address_data->data)[2], + (int)((uint8_t *)address_data->data)[1], + (int)((uint8_t *)address_data->data)[0]); break; case 16: (void)snprintf(name, sizeof(name), - "%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx." - "%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx." - "%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx." - "%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.ip6.arpa.", - (uint8_t)(((uint8_t *)address_data->data)[15] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[15] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[14] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[14] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[13] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[13] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[12] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[12] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[11] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[11] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[10] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[10] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[9] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[9] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[8] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[8] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[7] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[7] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[6] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[6] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[5] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[5] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[4] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[4] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[3] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[3] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[2] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[2] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[1] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[1] >> 4), - (uint8_t)(((uint8_t *)address_data->data)[0] & 0x0F), - (uint8_t)(((uint8_t *)address_data->data)[0] >> 4)); + "%x.%x.%x.%x.%x.%x.%x.%x." + "%x.%x.%x.%x.%x.%x.%x.%x." + "%x.%x.%x.%x.%x.%x.%x.%x." + "%x.%x.%x.%x.%x.%x.%x.%x.ip6.arpa.", + (int)(((uint8_t *)address_data->data)[15] & 0x0F), + (int)(((uint8_t *)address_data->data)[15] >> 4), + (int)(((uint8_t *)address_data->data)[14] & 0x0F), + (int)(((uint8_t *)address_data->data)[14] >> 4), + (int)(((uint8_t *)address_data->data)[13] & 0x0F), + (int)(((uint8_t *)address_data->data)[13] >> 4), + (int)(((uint8_t *)address_data->data)[12] & 0x0F), + (int)(((uint8_t *)address_data->data)[12] >> 4), + (int)(((uint8_t *)address_data->data)[11] & 0x0F), + (int)(((uint8_t *)address_data->data)[11] >> 4), + (int)(((uint8_t *)address_data->data)[10] & 0x0F), + (int)(((uint8_t *)address_data->data)[10] >> 4), + (int)(((uint8_t *)address_data->data)[9] & 0x0F), + (int)(((uint8_t *)address_data->data)[9] >> 4), + (int)(((uint8_t *)address_data->data)[8] & 0x0F), + (int)(((uint8_t *)address_data->data)[8] >> 4), + (int)(((uint8_t *)address_data->data)[7] & 0x0F), + (int)(((uint8_t *)address_data->data)[7] >> 4), + (int)(((uint8_t *)address_data->data)[6] & 0x0F), + (int)(((uint8_t *)address_data->data)[6] >> 4), + (int)(((uint8_t *)address_data->data)[5] & 0x0F), + (int)(((uint8_t *)address_data->data)[5] >> 4), + (int)(((uint8_t *)address_data->data)[4] & 0x0F), + (int)(((uint8_t *)address_data->data)[4] >> 4), + (int)(((uint8_t *)address_data->data)[3] & 0x0F), + (int)(((uint8_t *)address_data->data)[3] >> 4), + (int)(((uint8_t *)address_data->data)[2] & 0x0F), + (int)(((uint8_t *)address_data->data)[2] >> 4), + (int)(((uint8_t *)address_data->data)[1] & 0x0F), + (int)(((uint8_t *)address_data->data)[1] >> 4), + (int)(((uint8_t *)address_data->data)[0] & 0x0F), + (int)(((uint8_t *)address_data->data)[0] >> 4)); break; default: return GETDNS_RETURN_INVALID_PARAMETER; diff --git a/src/samplewin/Makefile.in b/src/samplewin/Makefile.in deleted file mode 100644 index 90a2d327..00000000 --- a/src/samplewin/Makefile.in +++ /dev/null @@ -1,150 +0,0 @@ -# -# @configure_input@ -# -# Copyright (c) 2013, Verisign, Inc., NLNet Labs -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the names of the copyright holders nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -package = @PACKAGE_NAME@ -version = @PACKAGE_VERSION@ -tarname = @PACKAGE_TARNAME@ -distdir = $(tarname)-$(version) - -prefix = @prefix@ -exec_prefix = @exec_prefix@ -bindir = @bindir@ -INSTALL = @INSTALL@ -LIBTOOL = ../../libtool - -srcdir = @srcdir@ - -have_libevent = @have_libevent@ -have_libuv = @have_libuv@ -have_libev = @have_libev@ -NOLIBCHECK = @NOLIBCHECK@ -NOLIBLDNS = @NOLIBLDNS@ - -EXTENSION_LIBEVENT_EXT_LIBS=@EXTENSION_LIBEVENT_EXT_LIBS@ -EXTENSION_LIBEVENT_LDFLAGS=@EXTENSION_LIBEVENT_LDFLAGS@ -EXTENSION_LIBUV_EXT_LIBS=@EXTENSION_LIBUV_EXT_LIBS@ -EXTENSION_LIBUV_LDFLAGS=@EXTENSION_LIBUV_LDFLAGS@ -EXTENSION_LIBEV_EXT_LIBS=@EXTENSION_LIBEV_EXT_LIBS@ -EXTENSION_LIBEV_LDFLAGS=@EXTENSION_LIBEV_LDFLAGS@ - -CHECK_GETDNS=@CHECK_GETDNS@ -CHECK_UV_PROG=@CHECK_UV_PROG@ -CHECK_EVENT_PROG=@CHECK_EVENT_PROG@ -CHECK_EV_PROG=@CHECK_EV_PROG@ - -CC=@CC@ -CFLAGS=-I$(srcdir)/.. -I$(srcdir) -I.. $(cflags) @CFLAGS@ -I/usr/local/ssl/include -LDFLAGS=-L.. @LDFLAGS@ -L/usr/local/ssl/lib -L/usr/local/lib/ -LDLIBS=../libgetdns.la @LIBS@ -lldns -lssl -lcrypto -lgdi32 -lws2_32 -liphlpapi -CHECK_LIBS=@CHECK_LIBS@ -CHECK_CFLAGS=@CHECK_CFLAGS@ -LDNS_LIBS=@LDNS_LIBS@ -LDNS_CFLAGS=@LDNS_CFLAGS@ -LDNS_LDFLAGS=@LDNS_LDFLAGS@ - -CHECK_OBJS=check_getdns_common.lo check_getdns_context_set_timeout.lo \ - check_getdns.lo check_getdns_transport.lo - -ALL_OBJS=$(CHECK_OBJS) getdns_query.lo - -PROGRAMS=getdns_query - -.SUFFIXES: .c .o .a .lo .h - -.c.o: - $(CC) $(CFLAGS) -c $< -o $@ - -.c.lo: - $(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) -c $< -o $@ - -default: all - -all: $(PROGRAMS) - -$(ALL_OBJS): - $(LIBTOOL) --quiet --tag=CC --mode=compile $(CC) $(CFLAGS) $(LDNS_CFLAGS) -c $(srcdir)/$(@:.lo=.c) -o $@ - -getdns_query: getdns_query.lo - $(LIBTOOL) --tag=CC --mode=link $(CC) $(CFLAGS) -o $@ getdns_query.lo $(LDFLAGS) $(LDLIBS) - - - -clean: - rm -f *.o *.lo $(PROGRAMS) scratchpad - rm -rf .libs - rm -f check_getdns.log - - -$(distdir): FORCE - mkdir -p $(distdir)/src - cp configure.ac $(distdir) - cp configure $(distdir) - cp Makefile.in $(distdir) - cp src/Makefile.in $(distdir)/src - -distcheck: $(distdir).tar.gz - gzip -cd $(distdir).tar.gz | tar xvf - - cd $(distdir) && ./configure - cd $(distdir) && $(MAKE) all - cd $(distdir) && $(MAKE) check - cd $(distdir) && $(MAKE) DESTDIR=$${PWD}/_inst install - cd $(distdir) && $(MAKE) DESTDIR=$${PWD}/_inst uninstall - @remaining="`find $${PWD}/$(distdir)/_inst -type f | wc -l`"; \ - if test "$${remaining}" -ne 0; then - echo "@@@ $${remaining} file(s) remaining in stage directory!"; \ - exit 1; \ - fi - cd $(distdir) && $(MAKE) clean - rm -rf $(distdir) - @echo "*** Package $(distdir).tar.gz is ready for distribution" - -Makefile: $(srcdir)/Makefile.in ../../config.status - cd ../.. && ./config.status src/test/Makefile - -configure.status: configure - cd ../.. && ./config.status --recheck - -depend: - (cd $(srcdir) ; awk 'BEGIN{P=1}{if(P)print}/^# Dependencies/{P=0}' Makefile.in > Makefile.in.new ) - (cd $(srcdir) ; gcc -MM -I. -I.. *.c | \ - sed -e 's? \([a-z_-]*\)\.\([ch]\)? $$(srcdir)/\1.\2?g' \ - -e 's? \$$(srcdir)/config\.h? ../config.h?g' \ - -e 's? $$(srcdir)/\.\./getdns/getdns_extra\.h? ../getdns/getdns_extra.h?g' \ - -e 's? \.\./getdns/getdns_ext_libevent\.h? $$(srcdir)/../getdns/getdns_ext_libevent.h?g' \ - -e 's? \.\./getdns/getdns_ext_libev\.h? $$(srcdir)/../getdns/getdns_ext_libev.h?g' \ - -e 's? \.\./getdns/getdns_ext_libuv\.h? $$(srcdir)/../getdns/getdns_ext_libuv.h?g' \ - -e 's!\(.*\)\.o[ :]*!\1.lo \1.o: !g' >> Makefile.in.new ) - (cd $(srcdir) ; diff Makefile.in.new Makefile.in && rm Makefile.in.new \ - || mv Makefile.in.new Makefile.in ) - - - -.PHONY: clean - -getdns_query.lo getdns_query.o: $(srcdir)/getdns_query.c ../config.h ../getdns/getdns.h \ - ../getdns/getdns_extra.h \ No newline at end of file diff --git a/src/samplewin/getdns_query.c b/src/samplewin/getdns_query.c deleted file mode 100644 index b2319ad8..00000000 --- a/src/samplewin/getdns_query.c +++ /dev/null @@ -1,1524 +0,0 @@ -/* - * Copyright (c) 2013, NLNet Labs, Verisign, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the names of the copyright holders nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include -#include -#include -#include -#include -#include -#include "util-internal.h" - -#define MAX_TIMEOUTS FD_SETSIZE - -/* Eventloop based on select */ -typedef struct my_eventloop { - getdns_eventloop base; - getdns_eventloop_event *fd_events[FD_SETSIZE]; - uint64_t fd_timeout_times[FD_SETSIZE]; - getdns_eventloop_event *timeout_events[MAX_TIMEOUTS]; - uint64_t timeout_times[MAX_TIMEOUTS]; -} my_eventloop; - -static uint64_t get_now_plus(uint64_t amount) -{ - struct timeval tv; - uint64_t now; - - if (gettimeofday(&tv, NULL)) { - perror("gettimeofday() failed"); - exit(EXIT_FAILURE); - } - now = tv.tv_sec * 1000000 + tv.tv_usec; - - return (now + amount * 1000) >= now ? now + amount * 1000 : -1; -} - -getdns_return_t -my_eventloop_schedule(getdns_eventloop *loop, - int fd, uint64_t timeout, getdns_eventloop_event *event) -{ - my_eventloop *my_loop = (my_eventloop *)loop; - size_t i; - - assert(loop); - assert(event); - assert(fd < FD_SETSIZE); - - DEBUG_SCHED( "%s(loop: %p, fd: %d, timeout: %"PRIu64", event: %p)\n" - , __FUNCTION__, loop, fd, timeout, event); - if (fd >= 0 && (event->read_cb || event->write_cb)) { - assert(my_loop->fd_events[fd] == NULL); - - my_loop->fd_events[fd] = event; - my_loop->fd_timeout_times[fd] = get_now_plus(timeout); - event->ev = (void *) (intptr_t) fd + 1; - - DEBUG_SCHED( "scheduled read/write at %d\n", fd); - return GETDNS_RETURN_GOOD; - } - - assert(event->timeout_cb && !event->read_cb && !event->write_cb); - - for (i = 0; i < MAX_TIMEOUTS; i++) { - if (my_loop->timeout_events[i] == NULL) { - my_loop->timeout_events[i] = event; - my_loop->timeout_times[i] = get_now_plus(timeout); - event->ev = (void *) (intptr_t) i + 1; - - DEBUG_SCHED( "scheduled timeout at %d\n", (int)i); - return GETDNS_RETURN_GOOD; - } - } - return GETDNS_RETURN_GENERIC_ERROR; -} - -getdns_return_t -my_eventloop_clear(getdns_eventloop *loop, getdns_eventloop_event *event) -{ - my_eventloop *my_loop = (my_eventloop *)loop; - size_t i; - - assert(loop); - assert(event); - - DEBUG_SCHED( "%s(loop: %p, event: %p)\n", __FUNCTION__, loop, event); - - i = (intptr_t)event->ev - 1; - assert(i >= 0 && i < FD_SETSIZE); - - if (event->timeout_cb && !event->read_cb && !event->write_cb) { - assert(my_loop->timeout_events[i] == event); - my_loop->timeout_events[i] = NULL; - } else { - assert(my_loop->fd_events[i] == event); - my_loop->fd_events[i] = NULL; - } - event->ev = NULL; - return GETDNS_RETURN_GOOD; -} - -void my_eventloop_cleanup(getdns_eventloop *loop) -{ -} - -void my_read_cb(int fd, getdns_eventloop_event *event) -{ - DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event); - event->read_cb(event->userarg); -} - -void my_write_cb(int fd, getdns_eventloop_event *event) -{ - DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event); - event->write_cb(event->userarg); -} - -void my_timeout_cb(int fd, getdns_eventloop_event *event) -{ - DEBUG_SCHED( "%s(fd: %d, event: %p)\n", __FUNCTION__, fd, event); - event->timeout_cb(event->userarg); -} - -void my_eventloop_run_once(getdns_eventloop *loop, int blocking) -{ - my_eventloop *my_loop = (my_eventloop *)loop; - - fd_set readfds, writefds; - int fd, max_fd = -1; - uint64_t now, timeout = (uint64_t)-1; - size_t i; - struct timeval tv; - - assert(loop); - - FD_ZERO(&readfds); - FD_ZERO(&writefds); - now = get_now_plus(0); - - for (i = 0; i < MAX_TIMEOUTS; i++) { - if (!my_loop->timeout_events[i]) - continue; - if (now > my_loop->timeout_times[i]) - my_timeout_cb(-1, my_loop->timeout_events[i]); - else if (my_loop->timeout_times[i] < timeout) - timeout = my_loop->timeout_times[i]; - } - for (fd = 0; fd < FD_SETSIZE; fd++) { - if (!my_loop->fd_events[fd]) - continue; - if (my_loop->fd_events[fd]->read_cb) - FD_SET(fd, &readfds); - if (my_loop->fd_events[fd]->write_cb) - FD_SET(fd, &writefds); - if (fd > max_fd) - max_fd = fd; - if (my_loop->fd_timeout_times[fd] < timeout) - timeout = my_loop->fd_timeout_times[fd]; - } - if (max_fd == -1 && timeout == (uint64_t)-1) - return; - - if (! blocking || now > timeout) { - tv.tv_sec = 0; - tv.tv_usec = 0; - } else { - tv.tv_sec = (timeout - now) / 1000000; - tv.tv_usec = (timeout - now) % 1000000; - } - if (select(max_fd + 1, &readfds, &writefds, NULL, &tv) < 0) { - perror("select() failed"); - exit(EXIT_FAILURE); - } - now = get_now_plus(0); - for (fd = 0; fd < FD_SETSIZE; fd++) { - if (my_loop->fd_events[fd] && - my_loop->fd_events[fd]->read_cb && - FD_ISSET(fd, &readfds)) - my_read_cb(fd, my_loop->fd_events[fd]); - - if (my_loop->fd_events[fd] && - my_loop->fd_events[fd]->write_cb && - FD_ISSET(fd, &writefds)) - my_write_cb(fd, my_loop->fd_events[fd]); - - if (my_loop->fd_events[fd] && - my_loop->fd_events[fd]->timeout_cb && - now > my_loop->fd_timeout_times[fd]) - my_timeout_cb(fd, my_loop->fd_events[fd]); - - i = fd; - if (my_loop->timeout_events[i] && - my_loop->timeout_events[i]->timeout_cb && - now > my_loop->timeout_times[i]) - my_timeout_cb(-1, my_loop->timeout_events[i]); - } -} - -void my_eventloop_run(getdns_eventloop *loop) -{ - my_eventloop *my_loop = (my_eventloop *)loop; - size_t i; - - assert(loop); - - i = 0; - while (i < MAX_TIMEOUTS) { - if (my_loop->fd_events[i] || my_loop->timeout_events[i]) { - my_eventloop_run_once(loop, 1); - i = 0; - } else { - i++; - } - } -} - -void my_eventloop_init(my_eventloop *loop) -{ - static getdns_eventloop_vmt my_eventloop_vmt = { - my_eventloop_cleanup, - my_eventloop_schedule, - my_eventloop_clear, - my_eventloop_run, - my_eventloop_run_once - }; - - (void) memset(loop, 0, sizeof(my_eventloop)); - loop->base.vmt = &my_eventloop_vmt; -} - -static int quiet = 0; -static int batch_mode = 0; -static char *query_file = NULL; -static int json = 0; -static char *the_root = "."; -static char *name; -static getdns_context *context; -static getdns_dict *extensions; -static uint16_t request_type = GETDNS_RRTYPE_NS; -static int timeout, edns0_size, padding_blocksize; -static int async = 0, interactive = 0; -static enum { GENERAL, ADDRESS, HOSTNAME, SERVICE } calltype = GENERAL; - -int get_rrtype(const char *t); - -getdns_dict * -ipaddr_dict(getdns_context *context, char *ipstr) -{ - getdns_dict *r = getdns_dict_create_with_context(context); - char *s = strchr(ipstr, '%'), *scope_id_str = ""; - char *p = strchr(ipstr, '@'), *portstr = ""; - char *t = strchr(ipstr, '#'), *tls_portstr = ""; - char *n = strchr(ipstr, '~'), *tls_namestr = ""; - uint8_t buf[sizeof(struct in6_addr)]; - getdns_bindata addr; - - addr.data = buf; - - if (!r) return NULL; - if (s) { - *s = 0; - scope_id_str = s + 1; - } - if (p) { - *p = 0; - portstr = p + 1; - } - if (t) { - *t = 0; - tls_portstr = t + 1; - } - if (n) { - *n = 0; - tls_namestr = n + 1; - } - if (strchr(ipstr, ':')) { - getdns_dict_util_set_string(r, "address_type", "IPv6"); - addr.size = 16; - if (inet_pton(AF_INET6, ipstr, buf) <= 0) { - getdns_dict_destroy(r); - return NULL; - } - } else { - getdns_dict_util_set_string(r, "address_type", "IPv4"); - addr.size = 4; - if (inet_pton(AF_INET, ipstr, buf) <= 0) { - getdns_dict_destroy(r); - return NULL; - } - } - getdns_dict_set_bindata(r, "address_data", &addr); - if (*portstr) - getdns_dict_set_int(r, "port", (int32_t)atoi(portstr)); - if (*tls_portstr) - getdns_dict_set_int(r, "tls_port", (int32_t)atoi(tls_portstr)); - if (*tls_namestr) { - getdns_dict_util_set_string(r, "tls_auth_name", tls_namestr); - } - if (*scope_id_str) - getdns_dict_util_set_string(r, "scope_id", scope_id_str); - - return r; -} - -static getdns_return_t -fill_transport_list(getdns_context *context, char *transport_list_str, - getdns_transport_list_t *transports, size_t *transport_count) -{ - size_t max_transports = *transport_count; - *transport_count = 0; - for ( size_t i = 0 - ; i < max_transports && i < strlen(transport_list_str) - ; i++, (*transport_count)++) { - switch(*(transport_list_str + i)) { - case 'U': - transports[i] = GETDNS_TRANSPORT_UDP; - break; - case 'T': - transports[i] = GETDNS_TRANSPORT_TCP; - break; - case 'L': - transports[i] = GETDNS_TRANSPORT_TLS; - break; - case 'S': - transports[i] = GETDNS_TRANSPORT_STARTTLS; - break; - default: - fprintf(stderr, "Unrecognised transport '%c' in string %s\n", - *(transport_list_str + i), transport_list_str); - return GETDNS_RETURN_GENERIC_ERROR; - } - } - return GETDNS_RETURN_GOOD; -} - -void -print_usage(FILE *out, const char *progname) -{ - fprintf(out, "usage: %s [@] [+extension] [] []\n", - progname); - fprintf(out, "options:\n"); - fprintf(out, "\t-a\tPerform asynchronous resolution " - "(default = synchronous)\n"); - fprintf(out, "\t-A\taddress lookup ( is ignored)\n"); - fprintf(out, "\t-B\tBatch mode. Schedule all messages before processing responses.\n"); - fprintf(out, "\t-b \tSet edns0 max_udp_payload size\n"); - fprintf(out, "\t-c\tSend Client Subnet privacy request\n"); - fprintf(out, "\t-D\tSet edns0 do bit\n"); - fprintf(out, "\t-d\tclear edns0 do bit\n"); - fprintf(out, "\t-e \tSet idle timeout in miliseconds\n"); - fprintf(out, "\t-F \tread the queries from the specified file\n"); - fprintf(out, "\t-G\tgeneral lookup\n"); - fprintf(out, "\t-H\thostname lookup. ( must be an IP address; is ignored)\n"); - fprintf(out, "\t-h\tPrint this help\n"); - fprintf(out, "\t-i\tPrint api information\n"); - fprintf(out, "\t-I\tInteractive mode (> 1 queries on same context)\n"); - fprintf(out, "\t-j\tOutput json response dict\n"); - fprintf(out, "\t-J\tPretty print json response dict\n"); - fprintf(out, "\t-k\tPrint root trust anchors\n"); - fprintf(out, "\t-n\tSet TLS authentication mode to NONE (default)\n"); - fprintf(out, "\t-m\tSet TLS authentication mode to HOSTNAME\n"); - fprintf(out, "\t-p\tPretty print response dict\n"); - fprintf(out, "\t-P \tPad TLS queries to a multiple of blocksize\n"); - fprintf(out, "\t-r\tSet recursing resolution type\n"); - fprintf(out, "\t-q\tQuiet mode - don't print response\n"); - fprintf(out, "\t-s\tSet stub resolution type (default = recursing)\n"); - fprintf(out, "\t-S\tservice lookup ( is ignored)\n"); - fprintf(out, "\t-t \tSet timeout in miliseconds\n"); - fprintf(out, "\t-T\tSet transport to TCP only\n"); - fprintf(out, "\t-O\tSet transport to TCP only keep connections open\n"); - fprintf(out, "\t-L\tSet transport to TLS only keep connections open\n"); - fprintf(out, "\t-E\tSet transport to TLS with TCP fallback only keep connections open\n"); - fprintf(out, "\t-R\tSet transport to STARTTLS with TCP fallback only keep connections open\n"); - fprintf(out, "\t-u\tSet transport to UDP with TCP fallback\n"); - fprintf(out, "\t-U\tSet transport to UDP only\n"); - fprintf(out, "\t-l \tSet transport list. List can contain 1 of each of the characters\n"); - fprintf(out, "\t\t\t U T L S for UDP, TCP, TLS or STARTTLS e.g 'UT' or 'LST' \n"); - -} - -static getdns_return_t validate_chain(getdns_dict *response) -{ - getdns_return_t r; - getdns_list *validation_chain; - getdns_list *replies_tree; - getdns_dict *reply; - getdns_list *to_validate; - getdns_list *trust_anchor; - size_t i; - int s; - - if (!(to_validate = getdns_list_create())) - return GETDNS_RETURN_MEMORY_ERROR; - - trust_anchor = getdns_root_trust_anchor(NULL); - - if ((r = getdns_dict_get_list( - response, "validation_chain", &validation_chain))) - goto error; - - if ((r = getdns_dict_get_list( - response, "replies_tree", &replies_tree))) - goto error; - - fprintf(stdout, "replies_tree dnssec_status: "); - switch ((s = getdns_validate_dnssec( - replies_tree, validation_chain, trust_anchor))) { - - case GETDNS_DNSSEC_SECURE: - fprintf(stdout, "GETDNS_DNSSEC_SECURE\n"); - break; - case GETDNS_DNSSEC_BOGUS: - fprintf(stdout, "GETDNS_DNSSEC_BOGUS\n"); - break; - case GETDNS_DNSSEC_INDETERMINATE: - fprintf(stdout, "GETDNS_DNSSEC_INDETERMINATE\n"); - break; - case GETDNS_DNSSEC_INSECURE: - fprintf(stdout, "GETDNS_DNSSEC_INSECURE\n"); - break; - case GETDNS_DNSSEC_NOT_PERFORMED: - fprintf(stdout, "GETDNS_DNSSEC_NOT_PERFORMED\n"); - break; - default: - fprintf(stdout, "%d\n", (int)s); - } - - i = 0; - while (!(r = getdns_list_get_dict(replies_tree, i++, &reply))) { - - if ((r = getdns_list_set_dict(to_validate, 0, reply))) - goto error; - - fprintf( stdout - , "reply %zu, dnssec_status: ", i); - switch ((s = getdns_validate_dnssec( - to_validate, validation_chain, trust_anchor))) { - - case GETDNS_DNSSEC_SECURE: - fprintf(stdout, "GETDNS_DNSSEC_SECURE\n"); - break; - case GETDNS_DNSSEC_BOGUS: - fprintf(stdout, "GETDNS_DNSSEC_BOGUS\n"); - break; - case GETDNS_DNSSEC_INDETERMINATE: - fprintf(stdout, "GETDNS_DNSSEC_INDETERMINATE\n"); - break; - case GETDNS_DNSSEC_INSECURE: - fprintf(stdout, "GETDNS_DNSSEC_INSECURE\n"); - break; - case GETDNS_DNSSEC_NOT_PERFORMED: - fprintf(stdout, "GETDNS_DNSSEC_NOT_PERFORMED\n"); - break; - default: - fprintf(stdout, "%d\n", (int)s); - } - } - if (r == GETDNS_RETURN_NO_SUCH_LIST_ITEM) - r = GETDNS_RETURN_GOOD; -error: - getdns_list_destroy(trust_anchor); - getdns_list_destroy(to_validate); - - return GETDNS_RETURN_GOOD; -} - -void callback(getdns_context *context, getdns_callback_type_t callback_type, - getdns_dict *response, void *userarg, getdns_transaction_t trans_id) -{ - char *response_str; - - /* This is a callback with data */; - if (response && !quiet && (response_str = json ? - getdns_print_json_dict(response, json == 1) - : getdns_pretty_print_dict(response))) { - - fprintf(stdout, "ASYNC response:\n%s\n", response_str); - validate_chain(response); - free(response_str); - } - - if (callback_type == GETDNS_CALLBACK_COMPLETE) { - fprintf(stdout, - "Response code was: GOOD. Status was: Callback with ID %llu was successfull.\n", - (unsigned long long)trans_id); - - } else if (callback_type == GETDNS_CALLBACK_CANCEL) - fprintf(stderr, - "An error occurred: The callback with ID %llu was cancelled. Exiting.\n", - (unsigned long long)trans_id); - else { - fprintf(stderr, - "An error occurred: The callback got a callback_type of %d. Exiting.\n", - callback_type); - fprintf(stderr, - "Error : '%s'\n", - getdns_get_errorstr_by_id(callback_type)); - } - getdns_dict_destroy(response); - response = NULL; -} - -#define CONTINUE ((getdns_return_t)-2) -#define CONTINUE_ERROR ((getdns_return_t)-3) - -static getdns_return_t set_cookie(getdns_dict *exts, char *cookie) -{ - uint8_t data[40]; - size_t i; - getdns_return_t r = GETDNS_RETURN_GENERIC_ERROR; - getdns_bindata bindata; - - getdns_dict *opt_parameters = getdns_dict_create(); - getdns_list *options = getdns_list_create(); - getdns_dict *option = getdns_dict_create(); - - if (*cookie == '=') - cookie++; - - for (i = 0; i < 40 && *cookie; i++) { - if (*cookie >= '0' && *cookie <= '9') - data[i] = (uint8_t)(*cookie - '0') << 4; - else if (*cookie >= 'a' && *cookie <= 'f') - data[i] = (uint8_t)(*cookie - 'a' + 10) << 4; - else if (*cookie >= 'A' && *cookie <= 'F') - data[i] = (uint8_t)(*cookie - 'A' + 10) << 4; - else - goto done; - cookie++; - if (*cookie >= '0' && *cookie <= '9') - data[i] |= (uint8_t)(*cookie - '0'); - else if (*cookie >= 'a' && *cookie <= 'f') - data[i] |= (uint8_t)(*cookie - 'a' + 10); - else if (*cookie >= 'A' && *cookie <= 'F') - data[i] |= (uint8_t)(*cookie - 'A' + 10); - else - goto done; - cookie++;; - } - bindata.data = data; - bindata.size = i; - if ((r = getdns_dict_set_int(option, "option_code", 10))) - goto done; - if ((r = getdns_dict_set_bindata(option, "option_data", &bindata))) - goto done; - if ((r = getdns_list_set_dict(options, 0, option))) - goto done; - if ((r = getdns_dict_set_list(opt_parameters, "options", options))) - goto done; - r = getdns_dict_set_dict(exts, "add_opt_parameters", opt_parameters); -done: - getdns_dict_destroy(option); - getdns_list_destroy(options); - getdns_dict_destroy(opt_parameters); - return r; -} - -getdns_return_t parse_args(int argc, char **argv) -{ - getdns_return_t r = GETDNS_RETURN_GOOD; - size_t i; - char *arg, *c, *endptr; - int t, print_api_info = 0, print_trust_anchors = 0; - getdns_list *upstream_list = NULL; - getdns_list *tas = NULL; - size_t upstream_count = 0; - - for (i = 1; i < argc; i++) { - arg = argv[i]; - if ((t = get_rrtype(arg)) >= 0) { - request_type = t; - continue; - - } else if (arg[0] == '+') { - if (arg[1] == 's' && arg[2] == 'i' && arg[3] == 't' && - (arg[4] == '=' || arg[4] == '\0')) { - if ((r = set_cookie(extensions, arg+4))) { - fprintf(stderr, "Could not set cookie:" - " %d", r); - break; - } - } else if (arg[1] == '0') { - /* Unset all existing extensions*/ - getdns_dict_destroy(extensions); - extensions = getdns_dict_create(); - break; - } else if ((r = getdns_dict_set_int(extensions, arg+1, - GETDNS_EXTENSION_TRUE))) { - fprintf(stderr, "Could not set extension " - "\"%s\": %d\n", argv[i], r); - break; - } - continue; - - } else if (arg[0] == '@') { - getdns_dict *upstream = ipaddr_dict(context, arg + 1); - if (upstream) { - if (!upstream_list && - !(upstream_list = - getdns_list_create_with_context(context))){ - fprintf(stderr, "Could not create upstream list\n"); - return GETDNS_RETURN_MEMORY_ERROR; - } - getdns_list_set_dict(upstream_list, - upstream_count++, upstream); - } - continue; - } else if (arg[0] != '-') { - name = arg; - continue; - } - for (c = arg+1; *c; c++) { - switch (*c) { - case 'a': - async = 1; - break; - case 'A': - calltype = ADDRESS; - break; - case 'b': - if (c[1] != 0 || ++i >= argc || !*argv[i]) { - fprintf(stderr, "max_udp_payload_size " - "expected after -b\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - edns0_size = strtol(argv[i], &endptr, 10); - if (*endptr || edns0_size < 0) { - fprintf(stderr, "positive " - "numeric max_udp_payload_size " - "expected after -b\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - getdns_context_set_edns_maximum_udp_payload_size( - context, (uint16_t) edns0_size); - goto next; - case 'c': - if (getdns_context_set_edns_client_subnet_private(context, 1)) - return GETDNS_RETURN_GENERIC_ERROR; - break; - case 'D': - (void) getdns_context_set_edns_do_bit(context, 1); - break; - case 'd': - (void) getdns_context_set_edns_do_bit(context, 0); - break; - case 'F': - if (c[1] != 0 || ++i >= argc || !*argv[i]) { - fprintf(stderr, "file name expected " - "after -F\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - query_file = argv[i]; - interactive = 1; - break; - case 'G': - calltype = GENERAL; - break; - case 'H': - calltype = HOSTNAME; - break; - case 'h': - print_usage(stdout, argv[0]); - return CONTINUE; - case 'i': - print_api_info = 1; - break; - case 'I': - interactive = 1; - break; - case 'j': - json = 2; - break; - case 'J': - json = 1; - break; - case 'k': - print_trust_anchors = 1; - break; - case 'n': - getdns_context_set_tls_authentication(context, - GETDNS_AUTHENTICATION_NONE); - break; - case 'm': - getdns_context_set_tls_authentication(context, - GETDNS_AUTHENTICATION_HOSTNAME); - break; - case 'P': - if (c[1] != 0 || ++i >= argc || !*argv[i]) { - fprintf(stderr, "tls_query_padding_blocksize " - "expected after -P\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - padding_blocksize = strtol(argv[i], &endptr, 10); - if (*endptr || padding_blocksize < 0) { - fprintf(stderr, "non-negative " - "numeric padding blocksize expected " - "after -P\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - if (getdns_context_set_tls_query_padding_blocksize( - context, padding_blocksize)) - return GETDNS_RETURN_GENERIC_ERROR; - goto next; - case 'p': - json = 0; - case 'q': - quiet = 1; - break; - case 'r': - getdns_context_set_resolution_type( - context, - GETDNS_RESOLUTION_RECURSING); - break; - case 's': - getdns_context_set_resolution_type( - context, GETDNS_RESOLUTION_STUB); - break; - case 'S': - calltype = SERVICE; - break; - case 't': - if (c[1] != 0 || ++i >= argc || !*argv[i]) { - fprintf(stderr, "timeout expected " - "after -t\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - timeout = strtol(argv[i], &endptr, 10); - if (*endptr || timeout < 0) { - fprintf(stderr, "positive " - "numeric timeout expected " - "after -t\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - getdns_context_set_timeout( - context, timeout); - goto next; - case 'e': - if (c[1] != 0 || ++i >= argc || !*argv[i]) { - fprintf(stderr, "idle timeout expected " - "after -t\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - timeout = strtol(argv[i], &endptr, 10); - if (*endptr || timeout < 0) { - fprintf(stderr, "positive " - "numeric idle timeout expected " - "after -t\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - getdns_context_set_idle_timeout( - context, timeout); - goto next; - case 'T': - getdns_context_set_dns_transport(context, - GETDNS_TRANSPORT_TCP_ONLY); - break; - case 'O': - getdns_context_set_dns_transport(context, - GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN); - break; - case 'L': - getdns_context_set_dns_transport(context, - GETDNS_TRANSPORT_TLS_ONLY_KEEP_CONNECTIONS_OPEN); - break; - case 'E': - getdns_context_set_dns_transport(context, - GETDNS_TRANSPORT_TLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN); - break; - case 'R': - getdns_context_set_dns_transport(context, - GETDNS_TRANSPORT_STARTTLS_FIRST_AND_FALL_BACK_TO_TCP_KEEP_CONNECTIONS_OPEN); - break; - case 'u': - getdns_context_set_dns_transport(context, - GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP); - break; - case 'U': - getdns_context_set_dns_transport(context, - GETDNS_TRANSPORT_UDP_ONLY); - break; - case 'l': - if (c[1] != 0 || ++i >= argc || !*argv[i]) { - fprintf(stderr, "transport list expected " - "after -l\n"); - return GETDNS_RETURN_GENERIC_ERROR; - } - getdns_transport_list_t transports[10]; - size_t transport_count = sizeof(transports); - if ((r = fill_transport_list(context, argv[i], transports, &transport_count)) || - (r = getdns_context_set_dns_transport_list(context, - transport_count, transports))){ - fprintf(stderr, "Could not set transports\n"); - return r; - } - break; - case 'B': - batch_mode = 1; - break; - - - default: - fprintf(stderr, "Unknown option " - "\"%c\"\n", *c); - for (i = 0; i < argc; i++) - fprintf(stderr, "%d: \"%s\"\n", (int)i, argv[i]); - return GETDNS_RETURN_GENERIC_ERROR; - } - } -next: ; - } - if (r) - return r; - if (upstream_count && - (r = getdns_context_set_upstream_recursive_servers( - context, upstream_list))) { - fprintf(stderr, "Error setting upstream recursive servers\n"); - } - if (print_api_info) { - fprintf(stdout, "%s\n", getdns_pretty_print_dict( - getdns_context_get_api_information(context))); - return CONTINUE; - } - if (print_trust_anchors) { - if ((tas = getdns_root_trust_anchor(NULL))) { - fprintf(stdout, "%s\n", getdns_pretty_print_list(tas)); - return CONTINUE; - } else - return CONTINUE_ERROR; - } - return r; -} - -getdns_return_t do_the_call(void) -{ - getdns_return_t r; - getdns_dict *address = NULL; - getdns_dict *response = NULL; - char *response_str; - uint32_t status; - - if (calltype == HOSTNAME && - !(address = ipaddr_dict(context, name))) { - fprintf(stderr, "Could not convert \"%s\" " - "to an IP address", name); - return GETDNS_RETURN_GOOD; - } - if (async) { - switch (calltype) { - case GENERAL: - r = getdns_general(context, name, request_type, - extensions, &response, NULL, callback); - break; - case ADDRESS: - r = getdns_address(context, name, - extensions, &response, NULL, callback); - break; - case HOSTNAME: - r = getdns_hostname(context, address, - extensions, &response, NULL, callback); - break; - case SERVICE: - r = getdns_service(context, name, - extensions, &response, NULL, callback); - break; - default: - r = GETDNS_RETURN_GENERIC_ERROR; - break; - } - if (r == GETDNS_RETURN_GOOD && !batch_mode) - getdns_context_run(context); - if (r != GETDNS_RETURN_GOOD) - fprintf(stderr, "An error occurred: %d '%s'\n", r, - getdns_get_errorstr_by_id(r)); - } else { - switch (calltype) { - case GENERAL: - r = getdns_general_sync(context, name, - request_type, extensions, &response); - break; - case ADDRESS: - r = getdns_address_sync(context, name, - extensions, &response); - break; - case HOSTNAME: - r = getdns_hostname_sync(context, address, - extensions, &response); - break; - case SERVICE: - r = getdns_service_sync(context, name, - extensions, &response); - break; - default: - r = GETDNS_RETURN_GENERIC_ERROR; - break; - } - if (r != GETDNS_RETURN_GOOD) { - fprintf(stderr, "An error occurred: %d '%s'\n", r, - getdns_get_errorstr_by_id(r)); - return r; - } - if (response && !quiet) { - if ((response_str = json ? - getdns_print_json_dict(response, json == 1) - : getdns_pretty_print_dict(response))) { - - fprintf( stdout, "SYNC response:\n%s\n" - , response_str); - validate_chain(response); - free(response_str); - } else { - r = GETDNS_RETURN_MEMORY_ERROR; - fprintf( stderr - , "Could not print response\n"); - } - } - getdns_dict_get_int(response, "status", &status); - fprintf(stdout, "Response code was: GOOD. Status was: %s\n", - getdns_get_errorstr_by_id(status)); - if (response) - getdns_dict_destroy(response); - } - return r; -} - -my_eventloop my_loop; -FILE *fp; - -void read_line_cb(void *userarg) -{ - getdns_eventloop_event *read_line_ev = userarg; - getdns_return_t r; - - char line[1024], *token, *linev[256]; - int linec; - - if (!fgets(line, 1024, fp) || !*line) { - if (query_file) - fprintf(stdout,"End of file."); - my_eventloop_clear(&my_loop.base, read_line_ev); - return; - } - if (query_file) - fprintf(stdout,"Found query: %s", line); - - linev[0] = __FILE__; - linec = 1; - if (!(token = strtok(line, " \t\f\n\r"))) { - if (! query_file) { - printf("> "); - fflush(stdout); - } - return; - } - if (*token == '#') { - fprintf(stdout,"Result: Skipping comment\n"); - if (! query_file) { - printf("> "); - fflush(stdout); - } - return; - } - do linev[linec++] = token; - while (linec < 256 && (token = strtok(NULL, " \t\f\n\r"))); - - if (((r = parse_args(linec, linev)) || (r = do_the_call())) && - (r != CONTINUE && r != CONTINUE_ERROR)) - my_eventloop_clear(&my_loop.base, read_line_ev); - - else if (! query_file) { - printf("> "); - fflush(stdout); - } -} - -int -main(int argc, char **argv) -{ - getdns_return_t r; - - name = the_root; - if ((r = getdns_context_create(&context, 1))) { - fprintf(stderr, "Create context failed: %d\n", r); - return r; - } - my_eventloop_init(&my_loop); - if ((r = getdns_context_set_eventloop(context, &my_loop.base))) - goto done_destroy_context; - if ((r = getdns_context_set_use_threads(context, 1))) - goto done_destroy_context; - extensions = getdns_dict_create(); - if (! extensions) { - fprintf(stderr, "Could not create extensions dict\n"); - r = GETDNS_RETURN_MEMORY_ERROR; - goto done_destroy_context; - } - if ((r = parse_args(argc, argv))) - goto done_destroy_context; - - if (query_file) { - fp = fopen(query_file, "rt"); - if (fp == NULL) { - fprintf(stderr, "Could not open query file: %s\n", query_file); - goto done_destroy_context; - } - } else - fp = stdin; - - /* Make the call */ - if (interactive) { - getdns_eventloop_event read_line_ev = { - &read_line_ev, read_line_cb, NULL, NULL, NULL }; - (void) my_eventloop_schedule( - &my_loop.base, fileno(fp), -1, &read_line_ev); - if (!query_file) { - printf("> "); - fflush(stdout); - } - my_eventloop_run(&my_loop.base); - } - else - r = do_the_call(); - - if ((r == GETDNS_RETURN_GOOD && batch_mode)) - getdns_context_run(context); - - /* Clean up */ - getdns_dict_destroy(extensions); -done_destroy_context: - getdns_context_destroy(context); - - if (fp) - fclose(fp); - - if (r == CONTINUE) - return 0; - else if (r == CONTINUE_ERROR) - return 1; - fprintf(stdout, "\nAll done.\n"); - return r; -} - -int get_rrtype(const char *t) { - char *endptr; - int r; - - switch (t[0]) { - case 'A': - case 'a': switch (t[1]) { - case '\0': return GETDNS_RRTYPE_A; - case '6': if (t[2] == '\0') return GETDNS_RRTYPE_A6; - return -1; - case 'A': - case 'a': /* before "AA", final "AA" (GETDNS_RRTYPE_AAAA) */ - if ((t[2]|0x20) == 'a' && (t[3]|0x20) == 'a' && t[4] == '\0') - return GETDNS_RRTYPE_AAAA; - return -1; - case 'F': - case 'f': /* before "AF", final "SDB" (GETDNS_RRTYPE_AFSDB) */ - if ((t[2]|0x20) == 's' && (t[3]|0x20) == 'd' && (t[4]|0x20) == 'b' && t[5] == '\0') - return GETDNS_RRTYPE_AFSDB; - return -1; - case 'P': - case 'p': /* before "AP", final "L" (GETDNS_RRTYPE_APL) */ - if ((t[2]|0x20) == 'l' && t[3] == '\0') - return GETDNS_RRTYPE_APL; - return -1; - case 'T': - case 't': /* before "AT", final "MA" (GETDNS_RRTYPE_ATMA) */ - if ((t[2]|0x20) == 'm' && (t[3]|0x20) == 'a' && t[4] == '\0') - return GETDNS_RRTYPE_ATMA; - return -1; - case 'X': - case 'x': /* before "AX", final "FR" (GETDNS_RRTYPE_AXFR) */ - if ((t[2]|0x20) == 'f' && (t[3]|0x20) == 'r' && t[4] == '\0') - return GETDNS_RRTYPE_AXFR; - return -1; - default : return -1; - }; - case 'C': - case 'c': switch (t[1]) { - case 'A': - case 'a': /* before "CA", final "A" (GETDNS_RRTYPE_CAA) */ - if ((t[2]|0x20) == 'a' && t[3] == '\0') - return GETDNS_RRTYPE_CAA; - return -1; - case 'D': - case 'd': switch (t[2]) { - case 'N': - case 'n': /* before "CDN", final "SKEY" (GETDNS_RRTYPE_CDNSKEY) */ - if ((t[3]|0x20) == 's' && (t[4]|0x20) == 'k' && (t[5]|0x20) == 'e' && (t[6]|0x20) == 'y' && t[7] == '\0') - return GETDNS_RRTYPE_CDNSKEY; - return -1; - case 'S': - case 's': if (t[3] == '\0') return GETDNS_RRTYPE_CDS; - return -1; - default : return -1; - }; - case 'E': - case 'e': /* before "CE", final "RT" (GETDNS_RRTYPE_CERT) */ - if ((t[2]|0x20) == 'r' && (t[3]|0x20) == 't' && t[4] == '\0') - return GETDNS_RRTYPE_CERT; - return -1; - case 'N': - case 'n': /* before "CN", final "AME" (GETDNS_RRTYPE_CNAME) */ - if ((t[2]|0x20) == 'a' && (t[3]|0x20) == 'm' && (t[4]|0x20) == 'e' && t[5] == '\0') - return GETDNS_RRTYPE_CNAME; - return -1; - case 'S': - case 's': /* before "CS", final "YNC" (GETDNS_RRTYPE_CSYNC) */ - if ((t[2]|0x20) == 'y' && (t[3]|0x20) == 'n' && (t[4]|0x20) == 'c' && t[5] == '\0') - return GETDNS_RRTYPE_CSYNC; - return -1; - - default : return -1; - }; - case 'D': - case 'd': switch (t[1]) { - case 'H': - case 'h': /* before "DH", final "CID" (GETDNS_RRTYPE_DHCID) */ - if ((t[2]|0x20) == 'c' && (t[3]|0x20) == 'i' && (t[4]|0x20) == 'd' && t[5] == '\0') - return GETDNS_RRTYPE_DHCID; - return -1; - case 'L': - case 'l': /* before "DL", final "V" (GETDNS_RRTYPE_DLV) */ - if ((t[2]|0x20) == 'v' && t[3] == '\0') - return GETDNS_RRTYPE_DLV; - return -1; - case 'N': - case 'n': switch (t[2]) { - case 'A': - case 'a': /* before "DNA", final "ME" (GETDNS_RRTYPE_DNAME) */ - if ((t[3]|0x20) == 'm' && (t[4]|0x20) == 'e' && t[5] == '\0') - return GETDNS_RRTYPE_DNAME; - return -1; - case 'S': - case 's': /* before "DNS", final "KEY" (GETDNS_RRTYPE_DNSKEY) */ - if ((t[3]|0x20) == 'k' && (t[4]|0x20) == 'e' && (t[5]|0x20) == 'y' && t[6] == '\0') - return GETDNS_RRTYPE_DNSKEY; - return -1; - default : return -1; - }; - case 'S': - case 's': if (t[2] == '\0') return GETDNS_RRTYPE_DS; - return -1; - default : return -1; - }; - case 'E': - case 'e': switch (t[1]) { - case 'I': - case 'i': /* before "EI", final "D" (GETDNS_RRTYPE_EID) */ - if ((t[2]|0x20) == 'd' && t[3] == '\0') - return GETDNS_RRTYPE_EID; - return -1; - case 'U': - case 'u': /* before "EU", next "I" */ - if ((t[2]|0x20) != 'i') - return -1; - switch (t[3]) { - case '4': /* before "EUI4", final "8" (GETDNS_RRTYPE_EUI48) */ - if (t[4] == '8' && t[5] == '\0') - return GETDNS_RRTYPE_EUI48; - return -1; - case '6': /* before "EUI6", final "4" (GETDNS_RRTYPE_EUI64) */ - if (t[4] == '4' && t[5] == '\0') - return GETDNS_RRTYPE_EUI64; - return -1; - default : return -1; - }; - default : return -1; - }; - case 'G': - case 'g': switch (t[1]) { - case 'I': - case 'i': /* before "GI", final "D" (GETDNS_RRTYPE_GID) */ - if ((t[2]|0x20) == 'd' && t[3] == '\0') - return GETDNS_RRTYPE_GID; - return -1; - case 'P': - case 'p': /* before "GP", final "OS" (GETDNS_RRTYPE_GPOS) */ - if ((t[2]|0x20) == 'o' && (t[3]|0x20) == 's' && t[4] == '\0') - return GETDNS_RRTYPE_GPOS; - return -1; - default : return -1; - }; - case 'H': - case 'h': /* before "H", next "I" */ - if ((t[1]|0x20) != 'i') - return -1; - switch (t[2]) { - case 'N': - case 'n': /* before "HIN", final "FO" (GETDNS_RRTYPE_HINFO) */ - if ((t[3]|0x20) == 'f' && (t[4]|0x20) == 'o' && t[5] == '\0') - return GETDNS_RRTYPE_HINFO; - return -1; - case 'P': - case 'p': if (t[3] == '\0') return GETDNS_RRTYPE_HIP; - return -1; - default : return -1; - }; - case 'I': - case 'i': switch (t[1]) { - case 'P': - case 'p': /* before "IP", final "SECKEY" (GETDNS_RRTYPE_IPSECKEY) */ - if ((t[2]|0x20) == 's' && (t[3]|0x20) == 'e' && (t[4]|0x20) == 'c' && (t[5]|0x20) == 'k' && (t[6]|0x20) == 'e' && (t[7]|0x20) == 'y' && t[8] == '\0') - return GETDNS_RRTYPE_IPSECKEY; - return -1; - case 'S': - case 's': /* before "IS", final "DN" (GETDNS_RRTYPE_ISDN) */ - if ((t[2]|0x20) == 'd' && (t[3]|0x20) == 'n' && t[4] == '\0') - return GETDNS_RRTYPE_ISDN; - return -1; - case 'X': - case 'x': /* before "IX", final "FR" (GETDNS_RRTYPE_IXFR) */ - if ((t[2]|0x20) == 'f' && (t[3]|0x20) == 'r' && t[4] == '\0') - return GETDNS_RRTYPE_IXFR; - return -1; - default : return -1; - }; - case 'K': - case 'k': switch (t[1]) { - case 'E': - case 'e': /* before "KE", final "Y" (GETDNS_RRTYPE_KEY) */ - if ((t[2]|0x20) == 'y' && t[3] == '\0') - return GETDNS_RRTYPE_KEY; - return -1; - case 'X': - case 'x': if (t[2] == '\0') return GETDNS_RRTYPE_KX; - return -1; - default : return -1; - }; - case 'L': - case 'l': switch (t[1]) { - case '3': /* before "L3", final "2" (GETDNS_RRTYPE_L32) */ - if (t[2] == '2' && t[3] == '\0') - return GETDNS_RRTYPE_L32; - return -1; - case '6': /* before "L6", final "4" (GETDNS_RRTYPE_L64) */ - if (t[2] == '4' && t[3] == '\0') - return GETDNS_RRTYPE_L64; - return -1; - case 'O': - case 'o': /* before "LO", final "C" (GETDNS_RRTYPE_LOC) */ - if ((t[2]|0x20) == 'c' && t[3] == '\0') - return GETDNS_RRTYPE_LOC; - return -1; - case 'P': - case 'p': if (t[2] == '\0') return GETDNS_RRTYPE_LP; - return -1; - default : return -1; - }; - case 'M': - case 'm': switch (t[1]) { - case 'A': - case 'a': /* before "MA", next "IL" */ - if ((t[2]|0x20) != 'i' && (t[3]|0x20) != 'l') - return -1; - switch (t[4]) { - case 'A': - case 'a': if (t[5] == '\0') return GETDNS_RRTYPE_MAILA; - return -1; - case 'B': - case 'b': if (t[5] == '\0') return GETDNS_RRTYPE_MAILB; - return -1; - default : return -1; - }; - case 'B': - case 'b': if (t[2] == '\0') return GETDNS_RRTYPE_MB; - return -1; - case 'D': - case 'd': if (t[2] == '\0') return GETDNS_RRTYPE_MD; - return -1; - case 'F': - case 'f': if (t[2] == '\0') return GETDNS_RRTYPE_MF; - return -1; - case 'G': - case 'g': if (t[2] == '\0') return GETDNS_RRTYPE_MG; - return -1; - case 'I': - case 'i': /* before "MI", final "NFO" (GETDNS_RRTYPE_MINFO) */ - if ((t[2]|0x20) == 'n' && (t[3]|0x20) == 'f' && (t[4]|0x20) == 'o' && t[5] == '\0') - return GETDNS_RRTYPE_MINFO; - return -1; - case 'R': - case 'r': if (t[2] == '\0') return GETDNS_RRTYPE_MR; - return -1; - case 'X': - case 'x': if (t[2] == '\0') return GETDNS_RRTYPE_MX; - return -1; - default : return -1; - }; - case 'N': - case 'n': switch (t[1]) { - case 'A': - case 'a': /* before "NA", final "PTR" (GETDNS_RRTYPE_NAPTR) */ - if ((t[2]|0x20) == 'p' && (t[3]|0x20) == 't' && (t[4]|0x20) == 'r' && t[5] == '\0') - return GETDNS_RRTYPE_NAPTR; - return -1; - case 'I': - case 'i': switch (t[2]) { - case 'D': - case 'd': if (t[3] == '\0') return GETDNS_RRTYPE_NID; - return -1; - case 'M': - case 'm': /* before "NIM", final "LOC" (GETDNS_RRTYPE_NIMLOC) */ - if ((t[3]|0x20) == 'l' && (t[4]|0x20) == 'o' && (t[5]|0x20) == 'c' && t[6] == '\0') - return GETDNS_RRTYPE_NIMLOC; - return -1; - case 'N': - case 'n': /* before "NIN", final "FO" (GETDNS_RRTYPE_NINFO) */ - if ((t[3]|0x20) == 'f' && (t[4]|0x20) == 'o' && t[5] == '\0') - return GETDNS_RRTYPE_NINFO; - return -1; - default : return -1; - }; - case 'S': - case 's': switch (t[2]) { - case '\0': return GETDNS_RRTYPE_NS; - case 'A': - case 'a': /* before "NSA", final "P" (GETDNS_RRTYPE_NSAP) */ - if ((t[3]|0x20) == 'p' && t[4] == '\0') - return GETDNS_RRTYPE_NSAP; - return -1; - case 'E': - case 'e': /* before "NSE", final "C3PARAM" (GETDNS_RRTYPE_NSEC3PARAM) */ - if ((t[3]|0x20) == 'c' && t[4] == '3' && (t[5]|0x20) == 'p' && (t[6]|0x20) == 'a' && (t[7]|0x20) == 'r' && (t[8]|0x20) == 'a' && (t[9]|0x20) == 'm' && t[10] == '\0') - return GETDNS_RRTYPE_NSEC3PARAM; - return -1; - default : return -1; - }; - case 'U': - case 'u': /* before "NU", final "LL" (GETDNS_RRTYPE_NULL) */ - if ((t[2]|0x20) == 'l' && (t[3]|0x20) == 'l' && t[4] == '\0') - return GETDNS_RRTYPE_NULL; - return -1; - case 'X': - case 'x': /* before "NX", final "T" (GETDNS_RRTYPE_NXT) */ - if ((t[2]|0x20) == 't' && t[3] == '\0') - return GETDNS_RRTYPE_NXT; - return -1; - default : return -1; - }; - case 'O': - case 'o': /* before "O", next "P" */ - if ((t[1]|0x20) != 'p') - return -1; - switch (t[2]) { - case 'E': - case 'e': /* before "OPE", final "NPGPKEY" (GETDNS_RRTYPE_OPENPGPKEY) */ - if ((t[3]|0x20) == 'n' && (t[4]|0x20) == 'p' && (t[5]|0x20) == 'g' && (t[6]|0x20) == 'p' && (t[7]|0x20) == 'k' && (t[8]|0x20) == 'e' && (t[9]|0x20) == 'y' && t[10] == '\0') - return GETDNS_RRTYPE_OPENPGPKEY; - return -1; - case 'T': - case 't': if (t[3] == '\0') return GETDNS_RRTYPE_OPT; - return -1; - default : return -1; - }; - case 'P': - case 'p': switch (t[1]) { - case 'T': - case 't': /* before "PT", final "R" (GETDNS_RRTYPE_PTR) */ - if ((t[2]|0x20) == 'r' && t[3] == '\0') - return GETDNS_RRTYPE_PTR; - return -1; - case 'X': - case 'x': if (t[2] == '\0') return GETDNS_RRTYPE_PX; - return -1; - default : return -1; - }; - case 'R': - case 'r': switch (t[1]) { - case 'K': - case 'k': /* before "RK", final "EY" (GETDNS_RRTYPE_RKEY) */ - if ((t[2]|0x20) == 'e' && (t[3]|0x20) == 'y' && t[4] == '\0') - return GETDNS_RRTYPE_RKEY; - return -1; - case 'P': - case 'p': if (t[2] == '\0') return GETDNS_RRTYPE_RP; - return -1; - case 'R': - case 'r': /* before "RR", final "SIG" (GETDNS_RRTYPE_RRSIG) */ - if ((t[2]|0x20) == 's' && (t[3]|0x20) == 'i' && (t[4]|0x20) == 'g' && t[5] == '\0') - return GETDNS_RRTYPE_RRSIG; - return -1; - case 'T': - case 't': if (t[2] == '\0') return GETDNS_RRTYPE_RT; - return -1; - default : return -1; - }; - case 'S': - case 's': switch (t[1]) { - case 'I': - case 'i': switch (t[2]) { - case 'G': - case 'g': if (t[3] == '\0') return GETDNS_RRTYPE_SIG; - return -1; - case 'N': - case 'n': /* before "SIN", final "K" (GETDNS_RRTYPE_SINK) */ - if ((t[3]|0x20) == 'k' && t[4] == '\0') - return GETDNS_RRTYPE_SINK; - return -1; - default : return -1; - }; - case 'O': - case 'o': /* before "SO", final "A" (GETDNS_RRTYPE_SOA) */ - if ((t[2]|0x20) == 'a' && t[3] == '\0') - return GETDNS_RRTYPE_SOA; - return -1; - case 'P': - case 'p': /* before "SP", final "F" (GETDNS_RRTYPE_SPF) */ - if ((t[2]|0x20) == 'f' && t[3] == '\0') - return GETDNS_RRTYPE_SPF; - return -1; - case 'R': - case 'r': /* before "SR", final "V" (GETDNS_RRTYPE_SRV) */ - if ((t[2]|0x20) == 'v' && t[3] == '\0') - return GETDNS_RRTYPE_SRV; - return -1; - case 'S': - case 's': /* before "SS", final "HFP" (GETDNS_RRTYPE_SSHFP) */ - if ((t[2]|0x20) == 'h' && (t[3]|0x20) == 'f' && (t[4]|0x20) == 'p' && t[5] == '\0') - return GETDNS_RRTYPE_SSHFP; - return -1; - default : return -1; - }; - case 'T': - case 't': switch (t[1]) { - case 'A': - case 'a': /* before "TA", final "LINK" (GETDNS_RRTYPE_TALINK) */ - if ((t[2]|0x20) == 'l' && (t[3]|0x20) == 'i' && (t[4]|0x20) == 'n' && (t[5]|0x20) == 'k' && t[6] == '\0') - return GETDNS_RRTYPE_TALINK; - return -1; - case 'K': - case 'k': /* before "TK", final "EY" (GETDNS_RRTYPE_TKEY) */ - if ((t[2]|0x20) == 'e' && (t[3]|0x20) == 'y' && t[4] == '\0') - return GETDNS_RRTYPE_TKEY; - return -1; - case 'L': - case 'l': /* before "TL", final "SA" (GETDNS_RRTYPE_TLSA) */ - if ((t[2]|0x20) == 's' && (t[3]|0x20) == 'a' && t[4] == '\0') - return GETDNS_RRTYPE_TLSA; - return -1; - case 'S': - case 's': /* before "TS", final "IG" (GETDNS_RRTYPE_TSIG) */ - if ((t[2]|0x20) == 'i' && (t[3]|0x20) == 'g' && t[4] == '\0') - return GETDNS_RRTYPE_TSIG; - return -1; - case 'X': - case 'x': /* before "TX", final "T" (GETDNS_RRTYPE_TXT) */ - if ((t[2]|0x20) == 't' && t[3] == '\0') - return GETDNS_RRTYPE_TXT; - return -1; - case 'Y': - case 'y': /* before "TY", then "PE" followed by a number */ - if ((t[2]|0x20) == 'p' && (t[3]|0x20) == 'e' && t[4] != '\0') { - r = (int) strtol(t + 4, &endptr, 10); - if (*endptr == '\0') return r; - } - return -1; - default : return -1; - }; - case 'U': - case 'u': switch (t[1]) { - case 'I': - case 'i': switch (t[2]) { - case 'D': - case 'd': if (t[3] == '\0') return GETDNS_RRTYPE_UID; - return -1; - case 'N': - case 'n': /* before "UIN", final "FO" (GETDNS_RRTYPE_UINFO) */ - if ((t[3]|0x20) == 'f' && (t[4]|0x20) == 'o' && t[5] == '\0') - return GETDNS_RRTYPE_UINFO; - return -1; - default : return -1; - }; - case 'N': - case 'n': /* before "UN", final "SPEC" (GETDNS_RRTYPE_UNSPEC) */ - if ((t[2]|0x20) == 's' && (t[3]|0x20) == 'p' && (t[4]|0x20) == 'e' && (t[5]|0x20) == 'c' && t[6] == '\0') - return GETDNS_RRTYPE_UNSPEC; - return -1; - case 'R': - case 'r': /* before "UR", final "I" (GETDNS_RRTYPE_URI) */ - if ((t[2]|0x20) == 'i' && t[3] == '\0') - return GETDNS_RRTYPE_URI; - return -1; - default : return -1; - }; - case 'W': - case 'w': /* before "W", final "KS" (GETDNS_RRTYPE_WKS) */ - if ((t[1]|0x20) == 'k' && (t[2]|0x20) == 's' && t[3] == '\0') - return GETDNS_RRTYPE_WKS; - return -1; - case 'X': - case 'x': /* before "X", final "25" (GETDNS_RRTYPE_X25) */ - if (t[1] == '2' && t[2] == '5' && t[3] == '\0') - return GETDNS_RRTYPE_X25; - return -1; - default : return -1; - }; -} - diff --git a/src/stub.c b/src/stub.c index 3b8de972..e0d55148 100644 --- a/src/stub.c +++ b/src/stub.c @@ -639,7 +639,7 @@ stub_tcp_read(int fd, getdns_tcp_state *tcp, struct mem_funcs *mf, getdns_eventl tcp->read_pos = tcp->read_buf; tcp->to_read = 2; /* Packet size */ } - read = recv(fd, tcp->read_pos, tcp->to_read, 0); + read = recv(fd, (void *)tcp->read_pos, tcp->to_read, 0); if (read == -1) { #ifdef USE_WINSOCK printf("read (in tcp ) %s\n", @@ -649,7 +649,7 @@ stub_tcp_read(int fd, getdns_tcp_state *tcp, struct mem_funcs *mf, getdns_eventl if (WSAGetLastError() == WSAEINPROGRESS) return STUB_TCP_AGAIN; if (WSAGetLastError() == WSAEWOULDBLOCK) { - winsock_tcp_wouldblock(event, EV_READ); + winsock_tcp_wouldblock(event->ev, EV_READ); return STUB_TCP_AGAIN; } @@ -773,9 +773,10 @@ stub_tcp_write(int fd, getdns_tcp_state *tcp, getdns_network_req *netreq) #else #ifdef USE_WINSOCK - written = sendto(fd, netreq->query - 2, pkt_len + 2, - 0, (struct sockaddr *)&(netreq->upstream->addr), - netreq->upstream->addr_len); + written = sendto(fd, (const char *)(netreq->query - 2), + pkt_len + 2, 0, + (struct sockaddr *)&(netreq->upstream->addr), + netreq->upstream->addr_len); #else written = write(fd, netreq->query - 2, pkt_len + 2); @@ -1283,7 +1284,7 @@ stub_udp_read_cb(void *userarg) GETDNS_CLEAR_EVENT(dnsreq->loop, &netreq->event); - read = recvfrom(netreq->fd, netreq->response, + read = recvfrom(netreq->fd, (void *)netreq->response, netreq->max_udp_payload_size + 1, /* If read == max_udp_payload_size * then all is good. If read == * max_udp_payload_size + 1, then @@ -1363,7 +1364,8 @@ stub_udp_write_cb(void *userarg) return; /* too many upstream options */ } pkt_len = _getdns_network_req_add_tsig(netreq); - if ((ssize_t)pkt_len != sendto(netreq->fd, netreq->query, pkt_len, 0, + if ((ssize_t)pkt_len != sendto( + netreq->fd, (const void *)netreq->query, pkt_len, 0, (struct sockaddr *)&netreq->upstream->addr, netreq->upstream->addr_len)) { close(netreq->fd); @@ -1394,7 +1396,7 @@ upstream_read_cb(void *userarg) &upstream->upstreams->mf); else q = stub_tcp_read(upstream->fd, &upstream->tcp, - &upstream->upstreams->mf, &netreq->event); + &upstream->upstreams->mf, &upstream->event); switch (q) { case STUB_TCP_AGAIN: diff --git a/src/test/getdns_query.c b/src/test/getdns_query.c index 2d00c985..862b9c68 100644 --- a/src/test/getdns_query.c +++ b/src/test/getdns_query.c @@ -549,8 +549,7 @@ static getdns_return_t validate_chain(getdns_dict *response) if ((r = getdns_list_set_dict(to_validate, 0, reply))) goto error; - fprintf( stdout - , "reply %zu, dnssec_status: ", i); + printf("reply %u, dnssec_status: ", (unsigned)i); switch ((s = getdns_validate_dnssec( to_validate, validation_chain, trust_anchor))) { @@ -598,14 +597,13 @@ void callback(getdns_context *context, getdns_callback_type_t callback_type, } if (callback_type == GETDNS_CALLBACK_COMPLETE) { - fprintf(stdout, - "Response code was: GOOD. Status was: Callback with ID %llu was successfull.\n", - (unsigned long long)trans_id); + printf("Response code was: GOOD. Status was: Callback with ID %"PRIu64" was successfull.\n", + trans_id); } else if (callback_type == GETDNS_CALLBACK_CANCEL) fprintf(stderr, - "An error occurred: The callback with ID %llu was cancelled. Exiting.\n", - (unsigned long long)trans_id); + "An error occurred: The callback with ID %"PRIu64" was cancelled. Exiting.\n", + trans_id); else { fprintf(stderr, "An error occurred: The callback got a callback_type of %d. Exiting.\n", diff --git a/src/util/winsock_event.c b/src/util/winsock_event.c index 9bb78cf9..2df44558 100644 --- a/src/util/winsock_event.c +++ b/src/util/winsock_event.c @@ -58,7 +58,8 @@ log_err(const char *format, ...) { va_list args; va_start(args, format); - fprintf(stderr, "error", format, args); + fprintf(stderr, "error "); + fprintf(stderr, format, args); va_end(args); } @@ -353,7 +354,7 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait) DWORD ret; WSANETWORKEVENTS netev; struct _getdns_event* eventlist[WSK_MAX_ITEMS]; - int i, numwait = 0, startidx = 0, was_timeout = 0; + int i, numwait = 0, startidx = 0; int newstickies = 0; struct timeval nultm; @@ -379,7 +380,7 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait) base->waitfor[numwait++] = base->items[i]->hEvent; printf("winsock_event bmax=%d numwait=%d wait=%x " "timeout=%d hEvent %d\n", base->max, numwait, (int)wait, - (int)timeout, base->items[i]->hEvent); + (int)timeout, (int)base->items[i]->hEvent); if (numwait == WSK_MAX_ITEMS) break; /* sanity check */ } @@ -391,7 +392,6 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait) if(wait) { Sleep(timeout); } - was_timeout = 1; } else { //gv: do not schedule udp write @@ -409,7 +409,7 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait) 0 /* do not wait for all, just one will do */, wait?timeout:WSA_INFINITE, 0); /* we are not alertable (IO completion events) */ - printf("after wait %d %d\n", ret, numwait); + printf("after wait %d %d\n", (int)ret, numwait); if(ret == WSA_WAIT_IO_COMPLETION) { //printf("getdns: WSAWaitForMultipleEvents failed: WSA_WAIT_IO_COMPLETION"); return -1; @@ -419,7 +419,6 @@ int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait) return -1; } else if(ret == WSA_WAIT_TIMEOUT) { printf("timeout\n"); - was_timeout = 1; } else startidx = ret - WSA_WAIT_EVENT_0; } @@ -633,25 +632,6 @@ int _getdns_event_base_set(struct _getdns_event_base *base, struct _getdns_event return 0; } -/** -* Find a fd in the list of items. -* Note that not all items have a fd associated (those are -1). -* Signals are stored separately, and not searched. -* @param base: event base to look in. -* @param fd: what socket to look for. -* @return the index in the array, or -1 on failure. -*/ -static int -find_fd(struct _getdns_event_base* base, int fd) -{ - int i; - for (i = 0; imax; i++) { - if (base->items[i]->ev_fd == fd) - return i; - } - return -1; -} - int _getdns_event_add(struct _getdns_event *ev, struct timeval *tv) { printf( "event_add %p added=%d fd=%d tv=" ARG_LL "d %s%s%s\n", @@ -714,7 +694,7 @@ int _getdns_event_add(struct _getdns_event *ev, struct timeval *tv) wsa_strerror(WSAGetLastError())); /* automatically sets fd to nonblocking mode. * nonblocking cannot be disabled, until wsaES(fd, NULL, 0) */ - printf("\nWSAEventSelect %d events %d hEvent %d\n", ev->ev_fd, events, ev->hEvent); + printf("\nWSAEventSelect %d events %d hEvent %d\n", ev->ev_fd, (int)events, (int)ev->hEvent); if (WSAEventSelect(ev->ev_fd, ev->hEvent, events) != 0) { log_err("getdns: WSAEventSelect in getdns failed: %s", wsa_strerror(WSAGetLastError())); @@ -722,13 +702,13 @@ int _getdns_event_add(struct _getdns_event *ev, struct timeval *tv) if(ev->is_tcp && ev->stick_events && (ev->ev_events & ev->old_events)) { /* go to processing the sticky event right away */ - printf("\nWSAEventSelect sticky %d events %d hEvent %d\n", ev->ev_fd, events, ev->hEvent); + printf("\nWSAEventSelect sticky %d events %d hEvent %d\n", ev->ev_fd, (int)events, (int)ev->hEvent); ev->ev_base->tcp_reinvigorated = 1; } } if(tv && (ev->ev_events&EV_TIMEOUT)) { - printf("\nWSAEventSelect timeout %d hEvent %d\n", ev->ev_fd, ev->hEvent); + printf("\nWSAEventSelect timeout %d hEvent %d\n", ev->ev_fd, (int)ev->hEvent); #ifndef S_SPLINT_S struct timeval *now = ev->ev_base->time_tv; @@ -787,14 +767,8 @@ static struct _getdns_event_base* signal_base = NULL; /** signal handler */ static RETSIGTYPE sigh(int sig) { - struct getdns_event* ev; if(!signal_base || sig < 0 || sig >= MAX_SIG) return; - ev = signal_base->signals[sig]; - if(!ev) - return; - //g fptr_ok(fptr_whitelist_event(ev->ev_callback)); - //g (*ev->ev_callback)(sig, EV_SIGNAL, ev->ev_arg); } int _getdns_signal_add(struct _getdns_event *ev, struct timeval * ATTR_UNUSED(tv)) diff --git a/src/util/winsock_event.h b/src/util/winsock_event.h index 6083cfc5..e9bb5982 100644 --- a/src/util/winsock_event.h +++ b/src/util/winsock_event.h @@ -95,15 +95,15 @@ /* redefine the calls to different names so that there is no name * collision with other code that uses libevent names. (that uses libunbound)*/ -#define event_init winsockevent_init +#define _getdns_event_init winsockevent_init #define event_get_version winsockevent_get_version #define event_get_method winsockevent_get_method #define _getdns_event_base_dispatch winsockevent_base_dispatch #define event_base_loopexit winsockevent_base_loopexit #define _getdns_event_base_free winsockevent_base_free -#define event_set winsockevent_set -#define event_base_set winsockevent_base_set -#define event_add winsockevent_add +#define _getdns_event_set winsockevent_set +#define _getdns_event_base_set winsockevent_base_set +#define _getdns_event_add winsockevent_add #define _getdns_event_del winsockevent_del #define signal_add winsocksignal_add #define signal_del winsocksignal_del @@ -225,26 +225,26 @@ struct _getdns_event { char* wsa_strerror(DWORD err); void log_err(const char *format, ...); /** create event base */ -void *event_init(time_t* time_secs, struct timeval* time_tv); +void *_getdns_event_init(time_t* time_secs, struct timeval* time_tv); /** get version */ const char *event_get_version(void); /** get polling method (select,epoll) */ const char *event_get_method(void); /** run select in a loop */ -int event_base_dispatch(struct _getdns_event_base *); +int _getdns_event_base_dispatch(struct _getdns_event_base *); /** exit that loop */ int event_base_loopexit(struct _getdns_event_base *, struct timeval *); /** free event base. Free events yourself */ -void event_base_free(struct _getdns_event_base *); +void _getdns_event_base_free(struct _getdns_event_base *); /** set content of event */ -void event_set(struct _getdns_event *, int, short, void (*)(int, short, void *), void *); +void _getdns_event_set(struct _getdns_event *, int, short, void (*)(int, short, void *), void *); /** add event to a base. You *must* call this for every event. */ -int event_base_set(struct _getdns_event_base *, struct _getdns_event *); +int _getdns_event_base_set(struct _getdns_event_base *, struct _getdns_event *); /** add event to make it active. You may not change it with event_set anymore */ -int event_add(struct _getdns_event *, struct timeval *); +int _getdns_event_add(struct _getdns_event *, struct timeval *); /** remove event. You may change it again */ -int event_del(struct _getdns_event *); +int _getdns_event_del(struct _getdns_event *); #define evtimer_add(ev, tv) event_add(ev, tv) #define evtimer_del(ev) event_del(ev) @@ -282,14 +282,14 @@ void winsock_tcp_wouldblock(struct _getdns_event* ev, int eventbit); * @param arg: user argument to callback routine. * @return false on error. */ -static int winsock_register_wsaevent(struct _getdns_event_base* base, struct _getdns_event* ev, +int winsock_register_wsaevent(struct _getdns_event_base* base, struct _getdns_event* ev, WSAEVENT wsaevent, void (*cb)(int, short, void*), void* arg); /** * Unregister a wsaevent. User has to close the WSAEVENT itself. * @param ev: event data storage. */ -static void winsock_unregister_wsaevent(struct _getdns_event* ev); +void winsock_unregister_wsaevent(struct _getdns_event* ev); #endif /* USE_WINSOCK */ #endif /* UTIL_WINSOCK_EVENT_H */