]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_10] fix nsupdate test on windows
authorMark Andrews <marka@isc.org>
Thu, 8 Feb 2018 21:36:01 +0000 (13:36 -0800)
committerEvan Hunt <each@isc.org>
Thu, 8 Feb 2018 21:36:01 +0000 (13:36 -0800)
4888. [test] Initialize sockets correctly in sample-update so
that nsupdate system test will will run on Windows.
[RT #47097]

(cherry picked from commit 6757dc6488804da282aedce4a563cc17c5986442)
(cherry picked from commit 701a93f5a592e4652343e049aa495d409c3ee133)

CHANGES
lib/isc/win32/socket.c
lib/samples/sample-update.c

diff --git a/CHANGES b/CHANGES
index 208b71d0ffe6b7ed7ad5c9d81ff757a267a72126..b3bfb36061cd6aa57f73aabc1e552286c37bb908 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+4888.  [test]          Initialize sockets correctly in sample-update so
+                       that nsupdate system test will will run on Windows.
+                       [RT #47097]
+
 4886.  [doc]           Document dig -u in manpage. [RT #47150]
 
 4885.  [security]      update-policy rules that otherwise ignore the name
index f96eaa6cc6f6769140405dd575f3c2bfe9a898d4..13f35aabff19946d7325f08032bd8cc7ea84712b 100644 (file)
@@ -641,10 +641,10 @@ initialise(void) {
                exit(1);
        }
        /*
-        * The following APIs do not exist as functions in a library, but we must
-        * ask winsock for them.  They are "extensions" -- but why they cannot be
-        * actual functions is beyond me.  So, ask winsock for the pointers to the
-        * functions we need.
+        * The following APIs do not exist as functions in a library, but
+        * we must ask winsock for them.  They are "extensions" -- but why
+        * they cannot be actual functions is beyond me.  So, ask winsock
+        * for the pointers to the functions we need.
         */
        sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        INSIST(sock != INVALID_SOCKET);
index 92c686f5bfed004a3ea3925c15737685fc990767..e185cb408509b86ca9d5c62e8d635596730c3a70 100644 (file)
@@ -91,6 +91,31 @@ usage(void) {
        exit(1);
 }
 
+#ifdef _WIN32
+static void
+InitSockets(void) {
+        WORD wVersionRequested;
+        WSADATA wsaData;
+        int err;
+
+        wVersionRequested = MAKEWORD(2, 0);
+
+        err = WSAStartup(wVersionRequested, &wsaData);
+        if (err != 0) {
+                fprintf(stderr, "WSAStartup() failed: %d\n", err);
+                exit(1);
+        }
+}
+
+static void
+DestroySockets(void) {
+        WSACleanup();
+}
+#else
+#define InitSockets() ((void)0)
+#define DestroySockets() ((void)0)
+#endif
+
 static isc_boolean_t
 addserver(const char *server, isc_sockaddrlist_t *list,
           isc_sockaddr_t *sockaddr)
@@ -108,10 +133,12 @@ addserver(const char *server, isc_sockaddrlist_t *list,
 #ifdef AI_NUMERICSERV
        hints.ai_flags |= AI_NUMERICSERV;
 #endif
+       InitSockets();
        gaierror = getaddrinfo(server, port, &hints, &res);
        if (gaierror != 0) {
                fprintf(stderr, "getaddrinfo(%s) failed: %s\n",
                        server, gai_strerror(gaierror));
+               DestroySockets();
                return (ISC_FALSE);
        }
        INSIST(res->ai_addrlen <= sizeof(sockaddr->type));
@@ -120,6 +147,7 @@ addserver(const char *server, isc_sockaddrlist_t *list,
        ISC_LINK_INIT(sockaddr, link);
        ISC_LIST_APPEND(*list, sockaddr, link);
        freeaddrinfo(res);
+       DestroySockets();
        return (ISC_TRUE);
 }