[Win32] sample-gai.c should call WSAStartup()
I fail to get the lib/sample/sample-gai.c
to work on Windows since WSAStartup()
wasn't called anywhere AFAICS.
The replacement function getaddrinfo()
calls getservbyname()
(not replaced). This call fails due to a missing WSAStartup()
.
An easy fix would simply be:
--- a/lib/samples/sample-gai.c 2018-06-07 17:54:40
+++ a/lib/samples/sample-gai.c 2018-10-12 03:39:26
@@ -62,6 +62,17 @@
int
main(int argc, char *argv[]) {
+#ifdef _WIN32
+ WORD wVersionRequested = MAKEWORD(2, 2);
+ WSADATA wsaData;
+ int err = WSAStartup(wVersionRequested, &wsaData);
+
+ if (err != 0) {
+ fprintf(stderr, "WSAStartup() failed: %d\n", err);
+ return (1);
+ }
+#endif
+
if (argc < 2)
exit(1);
@@ -69,5 +80,8 @@
do_gai(AF_INET6, argv[1]);
do_gai(AF_UNSPEC, argv[1]);
+#ifdef _WIN32
+ WSACleanup();
+#endif
return (0);
}