diff options
author | Martin Willi <martin@revosec.ch> | 2013-10-16 17:27:19 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 15:52:59 +0200 |
commit | 87a79e6a037c79f73743ed4aa357747760314325 (patch) | |
tree | c711b39ab9a217e035d1ebe779a75390ffc002d5 /src/libstrongswan/utils | |
parent | fb81820796349ec353622b08f1391bcecab53582 (diff) | |
download | strongswan-87a79e6a037c79f73743ed4aa357747760314325.tar.bz2 strongswan-87a79e6a037c79f73743ed4aa357747760314325.tar.xz |
windows: Add utils_init/deinit functions to initialize Winsock2
Diffstat (limited to 'src/libstrongswan/utils')
-rw-r--r-- | src/libstrongswan/utils/utils.c | 20 | ||||
-rw-r--r-- | src/libstrongswan/utils/utils.h | 10 | ||||
-rw-r--r-- | src/libstrongswan/utils/windows.c | 35 | ||||
-rw-r--r-- | src/libstrongswan/utils/windows.h | 10 |
4 files changed, 75 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index fe3b32f6c..81eb2acec 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -48,6 +48,26 @@ ENUM(status_names, SUCCESS, 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. */ void memxor(u_int8_t dst[], u_int8_t src[], size_t n) diff --git a/src/libstrongswan/utils/utils.h b/src/libstrongswan/utils/utils.h index ca0d6b9a3..c14b9c11e 100644 --- a/src/libstrongswan/utils/utils.h +++ b/src/libstrongswan/utils/utils.h @@ -83,6 +83,16 @@ #include "utils/strerror.h" /** + * Initialize utility functions + */ +void utils_init(); + +/** + * Deinitialize utility functions + */ +void utils_deinit(); + +/** * Helper function that compares two strings for equality */ static inline bool streq(const char *x, const char *y) diff --git a/src/libstrongswan/utils/windows.c b/src/libstrongswan/utils/windows.c new file mode 100644 index 000000000..6627a6c32 --- /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 <http://www.fsf.org/copyleft/gpl.txt>. + * + * 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 c0a5198a5..110498060 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -42,6 +42,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) */ static inline long random(void) |