From: Martin Willi Date: Wed, 16 Oct 2013 15:27:19 +0000 (+0200) Subject: windows: Add utils_init/deinit functions to initialize Winsock2 X-Git-Tag: 5.2.0dr6~24^2~114 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87a79e6a037c79f73743ed4aa357747760314325;p=thirdparty%2Fstrongswan.git windows: Add utils_init/deinit functions to initialize Winsock2 --- diff --git a/src/libstrongswan/Makefile.am b/src/libstrongswan/Makefile.am index 35605074a1..711676a26e 100644 --- a/src/libstrongswan/Makefile.am +++ b/src/libstrongswan/Makefile.am @@ -112,6 +112,8 @@ AM_YFLAGS = -v -d if USE_WINDOWS libstrongswan_la_LIBADD += -lws2_32 + libstrongswan_la_SOURCES += \ + utils/windows.c endif if USE_DBGHELP diff --git a/src/libstrongswan/library.c b/src/libstrongswan/library.c index f152a8c1f4..b06a2d5a56 100644 --- a/src/libstrongswan/library.c +++ b/src/libstrongswan/library.c @@ -146,6 +146,7 @@ void library_deinit() arrays_deinit(); threads_deinit(); backtrace_deinit(); + utils_deinit(); free((void*)this->public.ns); free(this); @@ -259,6 +260,7 @@ bool library_init(char *settings, const char *namespace) ); lib = &this->public; + utils_init(); backtrace_init(); threads_init(); arrays_init(); diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index fe3b32f6c3..81eb2acec7 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -47,6 +47,26 @@ ENUM(status_names, SUCCESS, NEED_MORE, "NEED_MORE", ); +/** + * See header + */ +void utils_init() +{ +#ifdef WIN32 + windows_init(); +#endif /* WIN32 */ +} + +/** + * See header + */ +void utils_deinit() +{ +#ifdef WIN32 + windows_deinit(); +#endif /* WIN32 */ +} + /** * Described in header. */ diff --git a/src/libstrongswan/utils/utils.h b/src/libstrongswan/utils/utils.h index ca0d6b9a31..c14b9c11e0 100644 --- a/src/libstrongswan/utils/utils.h +++ b/src/libstrongswan/utils/utils.h @@ -82,6 +82,16 @@ #include "enum.h" #include "utils/strerror.h" +/** + * Initialize utility functions + */ +void utils_init(); + +/** + * Deinitialize utility functions + */ +void utils_deinit(); + /** * Helper function that compares two strings for equality */ diff --git a/src/libstrongswan/utils/windows.c b/src/libstrongswan/utils/windows.c new file mode 100644 index 0000000000..6627a6c32f --- /dev/null +++ b/src/libstrongswan/utils/windows.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2013 Martin Willi + * Copyright (C) 2013 revosec AG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "utils.h" + +/** + * See header + */ +void windows_init() +{ + WSADATA wsad; + + /* initialize winsock2 */ + WSAStartup(MAKEWORD(2, 2), &wsad); +} + +/** + * See header + */ +void windows_deinit() +{ + WSACleanup(); +} diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h index c0a5198a52..1104980606 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -41,6 +41,16 @@ typedef u_int uid_t; typedef u_int gid_t; +/** + * Initialize Windows libraries + */ +void windows_init(); + +/** + * Deinitialize windows libraries + */ +void windows_deinit(); + /** * Replacement for random(3) */