Windows needs special network init (#1034)

This commit is contained in:
Logan oos Even 2022-06-30 11:58:54 +02:00 committed by GitHub
parent cf23457d3b
commit 504a552c77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,6 +80,7 @@ static void term_handler (int sig) {
// -------------------------------------------------------------------------------------------------------
// PLATFORM-DEPENDANT CODE
SOCKET connect_to_management_port (n2n_portfwd_conf_t *ppp) {
@ -87,6 +88,23 @@ SOCKET connect_to_management_port (n2n_portfwd_conf_t *ppp) {
SOCKET ret;
struct sockaddr_in sock_addr;
#if defined(WIN32)
// Windows requires a call to WSAStartup() before it can work with sockets
WORD wVersionRequested;
WSADATA wsaData;
int err;
// Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
// tell the user that we could not find a usable Winsock DLL
traceEvent(TRACE_ERROR, "WSAStartup failed with error: %d\n", err);
return -1;
}
#endif
ret = socket (PF_INET, SOCK_DGRAM, 0);
if((int)ret < 0)
return -1;