]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
* Fix for windows compile; asctime_r compat, search for inet_ntop
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Mon, 29 Jan 2024 13:06:35 +0000 (14:06 +0100)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Mon, 29 Jan 2024 13:06:35 +0000 (14:06 +0100)
  in ws2_32, avoid double decl of inet_ntop, check for symlink call,
  include config.h in edns.c, have socket compare use correct
  signedness, add -u repo option to makewin.sh, fix quoting in
  makewin.sh and check return value of bind and connect in net.c
  for failure instead of a socket type.

Changelog
Makefile.in
compat/asctime_r.c [new file with mode: 0644]
configure.ac
edns.c
examples/ldns-keygen.c
makewin.sh
net.c

index a5477dee9892764cc50e19a0d3fa923186123f5a..4a7b245cb7c17b809efe67bc9dedabc8a2de837e 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,12 @@
        * Fix building documentation in build directory.
          Thanks Michael Tokarev
        * Updated the configure script for split openssl directories.
+       * Fix for windows compile; asctime_r compat, search for inet_ntop
+         in ws2_32, avoid double decl of inet_ntop, check for symlink call,
+         include config.h in edns.c, have socket compare use correct
+         signedness, add -u repo option to makewin.sh, fix quoting in
+         makewin.sh and check return value of bind and connect in net.c
+         for failure instead of a socket type.
 
 1.8.3  2022-08-15
        * bugfix #183: Assertion failure with OPT record without rdata.
index c793dd2ac42a8aded9708f7dbf68d10d5f241f2d..90fa0695d26e4dd505e9f7cf5b775f029c5e4b2d 100644 (file)
@@ -814,6 +814,7 @@ compat/ctime_r.lo compat/ctime_r.o: $(srcdir)/compat/ctime_r.c ldns/config.h
 compat/fake-rfc2553.lo compat/fake-rfc2553.o: $(srcdir)/compat/fake-rfc2553.c ldns/config.h ldns/common.h \
  $(srcdir)/compat/fake-rfc2553.h
 compat/gmtime_r.lo compat/gmtime_r.o: $(srcdir)/compat/gmtime_r.c ldns/config.h
+compat/asctime_r.lo compat/asctime_r.o: $(srcdir)/compat/asctime_r.c ldns/config.h
 compat/inet_aton.lo compat/inet_aton.o: $(srcdir)/compat/inet_aton.c ldns/config.h
 compat/inet_ntop.lo compat/inet_ntop.o: $(srcdir)/compat/inet_ntop.c ldns/config.h
 compat/inet_pton.lo compat/inet_pton.o: $(srcdir)/compat/inet_pton.c ldns/config.h
diff --git a/compat/asctime_r.c b/compat/asctime_r.c
new file mode 100644 (file)
index 0000000..63e5355
--- /dev/null
@@ -0,0 +1,16 @@
+#ifdef HAVE_CONFIG_H
+#include <ldns/config.h>
+#endif
+
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
+char *asctime_r(const struct tm *tm, char *buf)
+{
+       /* no thread safety. */
+       char* result = asctime(tm);
+       if(buf && result)
+               strcpy(buf, result);
+       return result;
+}
index ff76665c86db681c8ad5a84c1a4227cbe4f1f027..59af4962baeaab23458a4d8d868523e000bca849 100644 (file)
@@ -137,21 +137,22 @@ AC_CHECK_FUNC([socket],
 # modern OS X provides inet_ntop in -lc.
 # modern Solaris provides inet_ntop in -lsocket -lnsl.
 # older Solaris provides inet_ntop in -lresolv.
+# Windows provides inet_ntop in -lws2_32.
 AC_CHECK_FUNC([inet_ntop],
     [],
-    [AC_SEARCH_LIBS([inet_ntop], [socket c nsl resolv], [ac_cv_func_inet_ntop=yes])
+    [AC_SEARCH_LIBS([inet_ntop], [socket c nsl resolv ws2_32], [ac_cv_func_inet_ntop=yes])
 ])
 
 # modern Linux provides inet_pton in -lsocket.
 # modern OS X provides inet_pton in -lc.
 # modern Solaris provides inet_pton in -lsocket -lnsl.
 # older Solaris provides inet_pton in -lresolv.
+# Windows provides inet_pton in -lws2_32.
 AC_CHECK_FUNC([inet_pton],
     [],
-    [AC_SEARCH_LIBS([inet_pton], [socket c nsl resolv], [ac_cv_func_inet_pton=yes])
+    [AC_SEARCH_LIBS([inet_pton], [socket c nsl resolv ws2_32], [ac_cv_func_inet_pton=yes])
 ])
 
-
 AC_ARG_WITH(drill, AC_HELP_STRING([--with-drill],
  [Also build drill.]),
  [],[with_drill="no"])
@@ -736,7 +737,12 @@ case "$enable_rrtype_svcb_https" in
                ;;
 esac
 
-
+if echo "$tmp_LIBS" | grep "ws2_32" >/dev/null; then
+       if echo "$LIBSSL_LIBS" | grep "ws2_32" >/dev/null; then
+               # only need it once.
+               LIBSSL_LIBS=`echo "$LIBSSL_LIBS" | sed -e 's/ -lws2_32//' -e 's/^-lws2_32//'`
+       fi
+fi
 
 AC_SUBST(LIBSSL_CPPFLAGS)
 AC_SUBST(LIBSSL_LDFLAGS)
@@ -900,6 +906,29 @@ AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])],
 #endif])
 ACX_CHECK_SS_FAMILY
 
+AC_CHECK_DECLS([inet_pton,inet_ntop], [], [], [
+AC_INCLUDES_DEFAULT
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#endif
+
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+])
+
 # AC_FUNC_MALLOC suffers false failures and causes Asan failures.
 # AC_FUNC_MALLOC
 # AC_FUNC_REALLOC
@@ -909,6 +938,7 @@ AC_REPLACE_FUNCS(b64_ntop)
 AC_REPLACE_FUNCS(calloc)
 AC_REPLACE_FUNCS(timegm)
 AC_REPLACE_FUNCS(gmtime_r)
+AC_REPLACE_FUNCS(asctime_r)
 AC_REPLACE_FUNCS(ctime_r)
 AC_REPLACE_FUNCS(localtime_r)
 AC_REPLACE_FUNCS(isblank)
@@ -930,7 +960,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
        AC_DEFINE([HAVE_FORK_AVAILABLE], 1, [if fork is available for compile])
 ], [   AC_MSG_RESULT(no)
 ])
-AC_CHECK_FUNCS([endprotoent endservent sleep random fcntl strtoul bzero memset b32_ntop b32_pton])
+AC_CHECK_FUNCS([endprotoent endservent sleep random fcntl strtoul bzero memset b32_ntop b32_pton symlink])
 if test "x$HAVE_B32_NTOP" = "xyes"; then
        AC_SUBST(ldns_build_config_have_b32_ntop, 1)
 else
@@ -1114,6 +1144,9 @@ time_t timegm (struct tm *tm);
 #ifndef HAVE_GMTIME_R
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
 #endif
+#ifndef HAVE_ASCTIME_R
+char *asctime_r(const struct tm *tm, char *buf);
+#endif
 #ifndef HAVE_LOCALTIME_R
 struct tm *localtime_r(const time_t *timep, struct tm *result);
 #endif
@@ -1128,10 +1161,10 @@ int isascii(int c);
 int snprintf (char *str, size_t count, const char *fmt, ...);
 int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
 #endif /* HAVE_SNPRINTF */
-#ifndef HAVE_INET_PTON
+#if !defined(HAVE_INET_PTON) && !HAVE_DECL_INET_PTON
 int inet_pton(int af, const char* src, void* dst);
 #endif /* HAVE_INET_PTON */
-#ifndef HAVE_INET_NTOP
+#if !defined(HAVE_INET_NTOP) && !HAVE_DECL_INET_NTOP
 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
 #endif
 #ifndef HAVE_INET_ATON
@@ -1145,7 +1178,7 @@ size_t strlcpy(char *dst, const char *src, size_t siz);
 #endif
 
 #ifdef USE_WINSOCK
-#define SOCK_INVALID INVALID_SOCKET
+#define SOCK_INVALID ((INT_PTR)INVALID_SOCKET)
 #define close_socket(_s) do { if (_s != SOCK_INVALID) {closesocket(_s); _s = -1;} } while(0)
 #else
 #define SOCK_INVALID -1
diff --git a/edns.c b/edns.c
index 3d002d67ed8c8cd8375756be4334b73220501ee2..fe288c04dde55bb688c6991d8bcc3ab839642e17 100644 (file)
--- a/edns.c
+++ b/edns.c
@@ -10,6 +10,7 @@
  * See the file LICENSE for the license
  */
 
+#include <ldns/config.h>
 #include <ldns/ldns.h>
 
 #define LDNS_OPTIONLIST_INIT 8
index 2f690b69822303ac6cd4f6e372942787b43a06e9..351fc1b2f2e5f348421016b89880ca9eae4ce9d9 100644 (file)
@@ -75,9 +75,13 @@ create_symlink(const char *symlink_destination, const char *symlink_name)
        if (!symlink_name)
                return result;  /* no arg "-s" at all */
 
+#ifdef HAVE_SYMLINK
        if ((result = symlink(symlink_destination, symlink_name)) == -1) {
                fprintf(stderr, "Unable to create symlink %s -> %s: %s\n", symlink_name, symlink_destination, strerror(errno));
        }
+#else
+       fprintf(stderr, "Unable to create symlink %s -> %s: no symlink()\n", symlink_name, symlink_destination);
+#endif
        return result;
 }
 
index accc9058e75eb79070039da5df824a0a8864a99b..cadecd161488ad2d8a05d616d0d3a28907c62a1d 100755 (executable)
@@ -17,6 +17,7 @@ cross_flag_nonstatic=""
 RC="no"
 SNAPSHOT="no"
 CHECKOUT=""
+GITREPO=""
 # the destination is a zipfile in the start directory ldns-a.b.c.zip
 # the start directory is a git repository, and it is copied to build from.
 
@@ -49,6 +50,8 @@ while [ "$1" ]; do
                echo "  -s              snapshot, current date appended to version"
                echo "  -rc <nr>        release candidate, the number is added to version"
                echo "                  ldns-<version>rc<nr>."
+               echo "  -u git_url      Retrieve the source from the specified repository url."
+               echo "                  Detected from the working copy if not specified."
                echo "  -c <tag/br>     Checkout this tag or branch, (defaults to current"
                echo "                  branch)."
                echo "  -wssl <file>    Pass openssl.tar.gz file, use absolute path."
@@ -66,6 +69,10 @@ while [ "$1" ]; do
                RC="$2"
                shift
                ;;
+       "-u")
+               GITREPO="$2"
+               shift
+               ;;
        "-wssl")
                WINSSL="$2"
                shift
@@ -85,6 +92,10 @@ then
                 CHECKOUT=$( (git status | head -n 1 | awk '{print$3}') || echo develop)
         fi
 fi
+if [ -z "$GITREPO" ]
+then
+       GITREPO=`git config remote.origin.url`
+fi
 
 # this script creates a temp directory $cdir.
 # this directory contains subdirectories:
@@ -99,11 +110,11 @@ fi
 # sslinstall-nonstatic/ : install of nonstatic openssl compile
 
 info "exporting source into $cdir/ldns"
-git clone git://git.nlnetlabs.nl/ldns/ ldns || error_cleanup "git command failed"
+git clone "$GITREPO" ldns || error_cleanup "git command failed"
 (cd ldns; git checkout "$CHECKOUT") || error_cleanup "Could not checkout $CHECKOUT"
 #svn export . $cdir/ldns
 info "exporting source into $cdir/ldns-nonstatic"
-git clone git://git.nlnetlabs.nl/ldns/ ldns-nonstatic || error_cleanup "git command failed"
+git clone "$GITREPO" ldns-nonstatic || error_cleanup "git command failed"
 (cd ldns-nonstatic; git checkout "$CHECKOUT") || error_cleanup "Could not checkout $CHECKOUT"
 #svn export . $cdir/ldns-nonstatic
 
@@ -139,7 +150,7 @@ else
        sslflags="no-shared no-asm -DOPENSSL_NO_CAPIENG mingw"
 fi
 info "winssl: Configure $sslflags"
-CC="${warch}-w64-mingw32-gcc" AR="${warch}-w64-mingw32-ar" RANLIB="${warch}-w64-mingw32-ranlib" WINDRES="${warch}-w64-mingw32-windres" ./Configure --prefix="$sslinstall" "$sslflags" || error_cleanup "OpenSSL Configure failed"
+CC="${warch}-w64-mingw32-gcc" AR="${warch}-w64-mingw32-ar" RANLIB="${warch}-w64-mingw32-ranlib" WINDRES="${warch}-w64-mingw32-windres" ./Configure --prefix="$sslinstall" $sslflags || error_cleanup "OpenSSL Configure failed"
 info "winssl: make"
 make || error_cleanup "make failed for $WINSSL"
 info "winssl: make install_sw"
@@ -157,7 +168,7 @@ libtoolize -ci
 autoreconf -fi
 ldns_flag="--with-examples --with-drill"
 info "ldns: Configure $cross_flag $ldns_flag"
-$configure "$cross_flag" "$ldns_flag" || error_cleanup "ldns configure failed"
+$configure $cross_flag $ldns_flag || error_cleanup "ldns configure failed"
 info "ldns: make"
 make || error_cleanup "ldns make failed"
 # do not strip debug symbols, could be useful for stack traces
@@ -196,7 +207,7 @@ libtoolize -ci
 autoreconf -fi
 ldns_flag_nonstatic="--with-examples --with-drill"
 info "ldnsnonstatic: Configure $cross_flag_nonstatic $ldns_flag_nonstatic"
-$configure "$cross_flag_nonstatic" "$ldns_flag_nonstatic" || error_cleanup "ldns configure failed"
+$configure $cross_flag_nonstatic $ldns_flag_nonstatic || error_cleanup "ldns configure failed"
 info "ldnsnonstatic: make"
 make || error_cleanup "ldns make failed"
 # do not strip debug symbols, could be useful for stack traces
diff --git a/net.c b/net.c
index 57d4dff24dbe1d7776570adfef8a58204a91d984..8fc9c8c48d872fbd5096653c237585995b8361a9 100644 (file)
--- a/net.c
+++ b/net.c
@@ -201,14 +201,14 @@ ldns_tcp_connect_from(const struct sockaddr_storage *to, socklen_t tolen,
                return -1;
        }
 #endif
-       if (from && bind(sockfd, (const struct sockaddr*)from, fromlen) == SOCK_INVALID){
+       if (from && bind(sockfd, (const struct sockaddr*)from, fromlen) == -1){
                close_socket(sockfd);
                return -1;
        }
 
        /* perform nonblocking connect, to be able to wait with select() */
        ldns_sock_nonblock(sockfd);
-       if (connect(sockfd, (struct sockaddr*)to, tolen) == SOCK_INVALID) {
+       if (connect(sockfd, (struct sockaddr*)to, tolen) == -1) {
 #ifndef USE_WINSOCK
 #ifdef EINPROGRESS
                if(errno != EINPROGRESS) {