]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Mingw port of ldns examples. Compiles.
authorWouter Wijngaards <wouter@NLnetLabs.nl>
Wed, 18 Jun 2008 09:38:30 +0000 (09:38 +0000)
committerWouter Wijngaards <wouter@NLnetLabs.nl>
Wed, 18 Jun 2008 09:38:30 +0000 (09:38 +0000)
ldns-testns works (UDP, TCP).
index(3) changed to strchr(3) which is c99 standard.
removed duplicated arg-with-ssl from examples configure.ac, added crypto, gdi32, ws2_32, headers, srandom, fork, sleep checks.

drill/configure.ac
examples/configure.ac
examples/ldns-notify.c
examples/ldns-signzone.c
examples/ldns-testns.c
examples/ldns-testpkts.c
examples/ldnsd.c

index 4afbd9380222ce2e8c959e00a31d2dcc3b32a7f8..36de2ebc1a0d8bcaf8745e99d6849e83be172abc 100644 (file)
@@ -9,6 +9,7 @@ OURCPPFLAGS=''
 CPPFLAGS=${CPPFLAGS:-${OURCPPFLAGS}}
 OURCFLAGS='-g'
 CFLAGS=${CFLAGS:-${OURCFLAGS}}
+AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
 
 AC_AIX
 # Checks for programs.
index 92075a58112d4d04f5b3647d5bcb02d3d73646f9..3ff7bae6c56218ac3c254bc5c3416da585e1e4b4 100644 (file)
@@ -1,7 +1,7 @@
 #                                               -*- Autoconf -*-
 # Process this file with autoconf to produce a configure script.
 
-AC_PREREQ(2.57)
+AC_PREREQ(2.56)
 AC_INIT(ldns, 1.3.0, libdns@nlnetlabs.nl,libdns)
 AC_CONFIG_SRCDIR([ldns-read-zone.c])
 
@@ -9,6 +9,7 @@ OURCPPFLAGS=''
 CPPFLAGS=${CPPFLAGS:-${OURCPPFLAGS}}
 OURCFLAGS='-g'
 CFLAGS=${CFLAGS:-${OURCFLAGS}}
+AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
 
 AC_AIX
 # Checks for programs.
@@ -55,50 +56,6 @@ fi
 
 
 
-# Checks for libraries.
-# Check for SSL, original taken from
-# http://www.gnu.org/software/ac-archive/htmldoc/check_ssl.html and
-# modified for NSD and 
-# copied again for use in ldns
-AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
-                                    [enable SSL (will check /usr/local/ssl
-                            /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr/sfw /usr)]),[
-        ],[
-            withval="yes"
-        ])
-    if test x_$withval != x_no; then
-        AC_MSG_CHECKING(for SSL)
-        if test x_$withval = x_ -o x_$withval = x_yes; then
-            withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr/sfw /usr"
-        fi
-        for dir in $withval; do
-            ssldir="$dir"
-            if test -f "$dir/include/openssl/ssl.h"; then
-                found_ssl="yes";
-                AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.])
-                CPPFLAGS="$CPPFLAGS -I$ssldir/include";
-                break;
-            fi
-        done
-        if test x_$found_ssl != x_yes; then
-            AC_MSG_ERROR(Cannot find the SSL libraries in $withval)
-        else
-            AC_MSG_RESULT(found in $ssldir)
-            HAVE_SSL=yes
-            LDFLAGS="$LDFLAGS -L$ssldir/lib -lcrypto";
-            if test "x$enable_rpath" = xyes; then
-               RUNTIME_PATH="$RUNTIME_PATH -R$ssldir/lib"
-            fi
-            AC_CHECK_LIB(crypto, HMAC_CTX_init,, [
-                    AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
-                ])
-        fi
-        AC_SUBST(HAVE_SSL)
-       AC_SUBST(RUNTIME_PATH)
-    fi
-
-
-
 dnl routine to help check for needed compiler flags.
 # if the given code compiles without the flag, execute argument 4
 # if the given code only compiles with the flag, execute argument 3
@@ -187,8 +144,9 @@ AC_CHECK_TYPE(uint32_t, unsigned int)
 AC_CHECK_TYPE(uint64_t, unsigned long long)
 AC_CHECK_TYPE(ssize_t, int)
 
-AC_CHECK_HEADERS([sys/types.h getopt.h stdlib.h stdio.h assert.h netinet/in.h ctype.h time.h pcap.h arpa/inet.h sys/time.h sys/socket.h sys/select.h],,, [AC_INCLUDES_DEFAULT])
-AC_CHECK_HEADERS([netinet/in_systm.h net/if.h netinet/ip.h netinet/udp.h netinet/if_ether.h netinet/ip6.h],,, [
+AC_CHECK_HEADERS([sys/types.h getopt.h stdlib.h stdio.h assert.h netinet/in.h ctype.h time.h pcap.h arpa/inet.h sys/time.h sys/socket.h sys/select.h netdb.h],,, [AC_INCLUDES_DEFAULT])
+AC_CHECK_HEADERS([winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT])
+AC_CHECK_HEADERS([netinet/in_systm.h net/if.h netinet/ip.h netinet/udp.h netinet/igmp.h netinet/if_ether.h netinet/ip6.h],,, [
 AC_INCLUDES_DEFAULT 
 #ifdef HAVE_NETINET_IN_SYSTM_H
 #include <netinet/in_systm.h>
@@ -269,13 +227,40 @@ AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
         else
             AC_MSG_RESULT(found in $ssldir)
             HAVE_SSL=yes
-            LDFLAGS="$LDFLAGS -L$ssldir/lib -lcrypto";
+            LDFLAGS="$LDFLAGS -L$ssldir/lib";
+           LIBS="$LIBS -lcrypto"
             if test "x$enable_rpath" = xyes; then
                RUNTIME_PATH="$RUNTIME_PATH -R$ssldir/lib"
             fi
-            AC_CHECK_LIB(crypto, HMAC_CTX_init,, [
-                    AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
+
+            AC_MSG_CHECKING([for HMAC_CTX_init in -lcrypto])
+            AC_TRY_LINK(, [
+                int HMAC_CTX_init(void);
+                (void)HMAC_CTX_init();
+              ], [
+                AC_MSG_RESULT(yes)
+                AC_DEFINE([HAVE_HMAC_CTX_INIT], 1,
+                        [If you have HMAC_CTX_init])
+              ], [
+                AC_MSG_RESULT(no)
+                # check if -lwsock32 or -lgdi32 are needed.     
+                LIBS="$LIBS -lws2_32 -lgdi32"
+                AC_MSG_CHECKING([if -lcrypto needs -lgdi32])
+                AC_TRY_LINK([], [
+                    int HMAC_CTX_init(void);
+                    (void)HMAC_CTX_init();
+                  ],[
+                    AC_DEFINE([HAVE_HMAC_CTX_INIT], 1,
+                        [If you have HMAC_CTX_init])
+                    AC_MSG_RESULT(yes)
+                   AC_DEFINE([USE_WINSOCK], 1, [If we need to use WSA... functions])
+                  ],[
+                    AC_MSG_RESULT(no)
+                    AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or
+ higher is required])
                 ])
+            ])
+
         fi
         AC_SUBST(HAVE_SSL)
        AC_SUBST(RUNTIME_PATH)
@@ -327,7 +312,8 @@ AC_CHECK_LIB(pcap, pcap_open_offline,, [
        ]
 )
 
-AC_CHECK_FUNCS(isblank)
+AC_FUNC_FORK
+AC_CHECK_FUNCS(isblank srandom random sleep)
 
 AH_BOTTOM([
 
@@ -385,6 +371,24 @@ AH_BOTTOM([
 #include <netinet/if_ether.h>
 #endif
 
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+
+#ifndef HAVE_RANDOM
+/* random can be replaced by rand for ldnsexamples */
+#define random rand
+#endif
+
+#ifndef HAVE_SRANDOM
+/* srandom can be replaced by srand for ldnsexamples */
+#define srandom srand
+#endif
+
 extern char *optarg;
 extern int optind, opterr;
 
index 21457ce37fca1763e7900af0ba12f31e28e7a5b8..d296a0d5bb1e35987cc6c60562f46c94d0e4639c 100644 (file)
@@ -11,7 +11,9 @@
 #include <config.h>
 
 #include <stdbool.h>
+#ifdef HAVE_NETDB_H
 #include <netdb.h>
+#endif
 #include <errno.h>
 
 /* ldns */
index c1ee9715df6accbb9ed3339d50c93c97220890f2..6d921a8817611b00a848f7be7034e03269e64131 100644 (file)
@@ -281,7 +281,7 @@ main(int argc, char *argv[])
                        }
                        break;
                case 'k':
-                       eng_key_l = index(optarg, ',');
+                       eng_key_l = strchr(optarg, ',');
                        if (eng_key_l && strlen(eng_key_l) > 1) {
                                if (eng_key_l > optarg) {
                                        eng_key_id_len = (size_t) (eng_key_l - optarg);
index 47a6853734e0c48ffee0b31af80159987eb04130..5b6f67e77cdad91ec43ef8cfa9aa3096132d89fd 100644 (file)
@@ -143,7 +143,9 @@ struct sockaddr_storage;
 #ifdef HAVE_NETINET_UDP_H
 #include <netinet/udp.h>
 #endif
+#ifdef HAVE_NETINET_IGMP_H
 #include <netinet/igmp.h>
+#endif
 #include <errno.h>
 
 #define INBUF_SIZE 4096         /* max size for incoming queries */
@@ -261,9 +263,9 @@ read_n_bytes(int sock, uint8_t* buf, size_t sz)
 {
        size_t count = 0;
        while(count < sz) {
-               ssize_t nb = read(sock, buf+count, sz-count);
+               ssize_t nb = recv(sock, buf+count, sz-count, 0);
                if(nb < 0) {
-                       log_msg("read(): %s\n", strerror(errno));
+                       log_msg("recv(): %s\n", strerror(errno));
                        return;
                }
                count += nb;
@@ -275,9 +277,9 @@ write_n_bytes(int sock, uint8_t* buf, size_t sz)
 {
        size_t count = 0;
        while(count < sz) {
-               ssize_t nb = write(sock, buf+count, sz-count);
+               ssize_t nb = send(sock, buf+count, sz-count, 0);
                if(nb < 0) {
-                       log_msg("write(): %s\n", strerror(errno));
+                       log_msg("send(): %s\n", strerror(errno));
                        return;
                }
                count += nb;
@@ -336,6 +338,10 @@ handle_tcp(int tcp_sock, struct entry* entries, int *count)
 static void
 forkit(int number)
 {
+#ifndef HAVE_FORK
+       log_msg("error: fork() not available\n");
+       exit(1);
+#else
        int i;
        for(i=0; i<number; i++)
        {
@@ -348,6 +354,7 @@ forkit(int number)
                        return; /* child starts serving */
                log_msg("forked pid: %d\n", (int)pid);
        }
+#endif
 }
 
 int
@@ -370,6 +377,10 @@ main(int argc, char **argv)
 
        /* dns */
        struct entry* entries;
+
+#ifdef USE_WINSOCK
+       WSADATA wsa_data;
+#endif
        
        /* parse arguments */
        srandom(time(NULL) ^ getpid());
@@ -417,6 +428,11 @@ main(int argc, char **argv)
        datafile = argv[0];
        log_msg("Reading datafile %s\n", datafile);
        entries = read_datafile(datafile);
+
+#ifdef USE_WINSOCK
+       if(WSAStartup(MAKEWORD(2,2), &wsa_data) != 0)
+               error("WSAStartup failed\n");
+#endif
        
        if((udp_sock = socket(fam, SOCK_DGRAM, 0)) < 0) {
                error("udp socket(): %s\n", strerror(errno));
@@ -425,7 +441,7 @@ main(int argc, char **argv)
                error("tcp socket(): %s\n", strerror(errno));
        }
        c = 1;
-       if(setsockopt(tcp_sock, SOL_SOCKET, SO_REUSEADDR, &c, (socklen_t) sizeof(int)) < 0) {
+       if(setsockopt(tcp_sock, SOL_SOCKET, SO_REUSEADDR, (void*)&c, (socklen_t) sizeof(int)) < 0) {
                error("setsockopt(SO_REUSEADDR): %s\n", strerror(errno));
        }
 
@@ -447,7 +463,13 @@ main(int argc, char **argv)
                        log_msg("trying to bind to port %d\n", port);
                        random_port_success = true;
                        if (bind_port(udp_sock, port, fam)) {
+#ifdef EADDRINUSE
                                if (errno != EADDRINUSE) {
+#elif defined(USE_WINSOCK)
+                               if (WSAGetLastError() != WSAEADDRINUSE) {
+#else
+                               if (1) {
+#endif
                                        perror("bind()");
                                        return -1;
                                } else {
@@ -456,7 +478,13 @@ main(int argc, char **argv)
                        }
                        if (random_port_success) {
                                if (bind_port(tcp_sock, port, fam)) {
+#ifdef EADDRINUSE
                                        if (errno != EADDRINUSE) {
+#elif defined(USE_WINSOCK)
+                                       if (WSAGetLastError()!=WSAEADDRINUSE){
+#else
+                                       if (1) {
+#endif
                                                perror("bind()");
                                                return -1;
                                        } else {
index aab3e6c7ea8860e753f12f82def2068153016965..b8317b25781f0223e147598b7ad71d9ce15e00f2 100644 (file)
@@ -708,7 +708,11 @@ adjust_packet(struct entry* match, ldns_pkt* answer_pkt, ldns_pkt* query_pkt)
        }
        if(match->sleeptime > 0) {
                verbose(3, "sleeping for %d seconds\n", match->sleeptime);
+#ifdef HAVE_SLEEP
                sleep(match->sleeptime);
+#else
+               Sleep(match->sleeptime * 1000);
+#endif
        }
 }
 
@@ -808,7 +812,11 @@ handle_query(uint8_t* inbuf, ssize_t inlen, struct entry* entries, int* count,
                if(p->packet_sleep) {
                        verbose(3, "sleeping for next packet %d secs\n", 
                                p->packet_sleep);
+#ifdef HAVE_SLEEP
                        sleep(p->packet_sleep);
+#else
+                       Sleep(p->packet_sleep * 1000);
+#endif
                        verbose(3, "wakeup for next packet "
                                "(slept %d secs)\n", p->packet_sleep);
                }
index ecc4e56d48cf7f1abfe4b3f3f99cf49092a4bead..c9c3619cad05e38a37a2fd552b536ed234790ad2 100644 (file)
 #include "config.h"
 #include <ldns/ldns.h>
 
-#include <sys/socket.h>
-
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <netinet/udp.h>
-#include <netinet/igmp.h>
+#ifdef HAVE_SYS_SOCKET_H
+#  include <sys/socket.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#  include <arpa/inet.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#  include <netinet/in.h>
+#endif
+#ifdef HAVE_NETINET_UDP_H
+#  include <netinet/udp.h>
+#endif
+#ifdef HAVE_NETINET_IGMP_H
+#  include <netinet/igmp.h>
+#endif
 
 #include <errno.h>