From: Mark Andrews Date: Thu, 8 Feb 2018 21:33:51 +0000 (-0800) Subject: [master] fix nsupdate test on windows X-Git-Tag: v9.13.0~180 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=6757dc6488804da282aedce4a563cc17c5986442;p=thirdparty%2Fbind9.git [master] fix nsupdate test on windows 4888. [test] Initialize sockets correctly in sample-update so that nsupdate system test will will run on Windows. [RT #47097] --- diff --git a/CHANGES b/CHANGES index 1f52d594ebf..11ae99876e3 100644 --- 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] + 4887. [test] Enable the rpzrecurse test to run on Windows. [RT #47093] diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 456873d5f7c..c63ad64f04b 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -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); diff --git a/lib/samples/sample-update.c b/lib/samples/sample-update.c index 231dc0dc03d..d1a019d36b0 100644 --- a/lib/samples/sample-update.c +++ b/lib/samples/sample-update.c @@ -83,6 +83,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) @@ -100,10 +125,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)); @@ -112,6 +139,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); }