]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
windows: Add utils_init/deinit functions to initialize Winsock2
authorMartin Willi <martin@revosec.ch>
Wed, 16 Oct 2013 15:27:19 +0000 (17:27 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:52:59 +0000 (15:52 +0200)
src/libstrongswan/Makefile.am
src/libstrongswan/library.c
src/libstrongswan/utils/utils.c
src/libstrongswan/utils/utils.h
src/libstrongswan/utils/windows.c [new file with mode: 0644]
src/libstrongswan/utils/windows.h

index 35605074a166b48fbfbad5ac7e0ef16d8f0acef5..711676a26e2e7f2321b64122977027f17b9fb809 100644 (file)
@@ -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
index f152a8c1f4562ec6fb15ae997e22436abf4ebf6b..b06a2d5a569de6ea6c5f7ff02c70f429724ba841 100644 (file)
@@ -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();
index fe3b32f6c329bc1a13cbdee33c78110fec43a692..81eb2acec72ecdd0a49eb5859152980d9eac120a 100644 (file)
@@ -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.
  */
index ca0d6b9a31948b654973f192175d618624dc4f5a..c14b9c11e0cd6d6ead062f5b8b76bbb85e9f74ef 100644 (file)
 #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 (file)
index 0000000..6627a6c
--- /dev/null
@@ -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();
+}
index c0a5198a52f3b98b0f66f11d3a478eb1ff42300d..11049806065dd72f3a07246fc0162943ee879e49 100644 (file)
 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)
  */