]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_9] fix nsupdate test on windows
authorMark Andrews <marka@isc.org>
Thu, 8 Feb 2018 21:36:44 +0000 (13:36 -0800)
committerEvan Hunt <each@isc.org>
Thu, 8 Feb 2018 21:36:44 +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)

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

diff --git a/CHANGES b/CHANGES
index 5a9e42960e7472400cca3bbed33dc2997932f931..e027e042e18a0ccf0f76e75493ea2200c8ec608e 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]
+
 4885.  [security]      update-policy rules that otherwise ignore the name
                        field now require that it be set to "." to ensure
                        that any type list present is properly interpreted.
index 225ff6ae50e3791dc9ea85432646c87dd216fb2c..dc2fd16c0d7d2e79cbd905fa90dd3a8d721fa57e 100644 (file)
@@ -87,6 +87,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)
@@ -104,10 +129,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));
@@ -116,6 +143,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);
 }
 
index 32972c5d3f0dd3ba68ce4316d10f258940a0bb5c..4cc1b22f8fc41e6040d4c419cf2c67bbc9b03b2f 100644 (file)
@@ -633,10 +633,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);