Skip to content

Commit

Permalink
* Fix for windows compile; asctime_r compat, search for inet_ntop
Browse files Browse the repository at this point in the history
  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.
  • Loading branch information
wcawijngaards committed Jan 29, 2024
1 parent f5cc03c commit e435a9f
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions compat/asctime_r.c
Original file line number Diff line number Diff line change
@@ -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;
}
49 changes: 41 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions edns.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* See the file LICENSE for the license
*/

#include <ldns/config.h>
#include <ldns/ldns.h>

#define LDNS_OPTIONLIST_INIT 8
Expand Down
4 changes: 4 additions & 0 deletions examples/ldns-keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 16 additions & 5 deletions makewin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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."
Expand All @@ -66,6 +69,10 @@ while [ "$1" ]; do
RC="$2"
shift
;;
"-u")
GITREPO="$2"
shift
;;
"-wssl")
WINSSL="$2"
shift
Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e435a9f

Please sign in to comment.