aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/includes/hicn/base.h5
-rw-r--r--lib/includes/hicn/common.h3
-rw-r--r--lib/includes/hicn/util/windows/dlfcn.h33
-rwxr-xr-xlib/includes/hicn/util/windows/windows_utils.h8
-rw-r--r--lib/src/CMakeLists.txt5
-rw-r--r--lib/src/util/windows/dlfcn.c65
6 files changed, 118 insertions, 1 deletions
diff --git a/lib/includes/hicn/base.h b/lib/includes/hicn/base.h
index 797912f91..1061724ce 100644
--- a/lib/includes/hicn/base.h
+++ b/lib/includes/hicn/base.h
@@ -22,8 +22,11 @@
#define HICN_BASE_H
#include "common.h"
+#ifdef _WIN32
+#include <Winsock2.h>
+#else
#include <netinet/in.h>
-
+#endif
/* Default header fields */
#define HICN_DEFAULT_TTL 254
diff --git a/lib/includes/hicn/common.h b/lib/includes/hicn/common.h
index a5ca2878b..05f8ad95f 100644
--- a/lib/includes/hicn/common.h
+++ b/lib/includes/hicn/common.h
@@ -104,6 +104,9 @@ typedef uword ip_csum_t;
/* Windows compatibility headers */
#define WIN32_LEAN_AND_MEAN
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <windows.h>
#include <winsock2.h>
#include <ws2ipdef.h>
diff --git a/lib/includes/hicn/util/windows/dlfcn.h b/lib/includes/hicn/util/windows/dlfcn.h
new file mode 100644
index 000000000..7775226cd
--- /dev/null
+++ b/lib/includes/hicn/util/windows/dlfcn.h
@@ -0,0 +1,33 @@
+/* dlfcn.h */
+
+#ifndef DLFCN_H
+#define DLFCN_H
+#define RTLD_GLOBAL 0x100 /* do not hide entries in this module */
+#define RTLD_LOCAL 0x000 /* hide entries in this module */
+
+#define RTLD_LAZY 0x000 /* accept unresolved externs */
+#define RTLD_NOW 0x001 /* abort if module has unresolved externs */
+
+/*
+ How to call in Windows:
+
+ void *h = dlopen ("path\\library.dll", flags)
+ void (*fun)() = dlsym (h, "entry")
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ void *dlopen (const char *filename, int flag);
+ int dlclose (void *handle);
+
+ void *dlsym (void *handle, const char *name);
+
+const char *dlerror (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif \ No newline at end of file
diff --git a/lib/includes/hicn/util/windows/windows_utils.h b/lib/includes/hicn/util/windows/windows_utils.h
index c4662af5e..d24aaadbf 100755
--- a/lib/includes/hicn/util/windows/windows_utils.h
+++ b/lib/includes/hicn/util/windows/windows_utils.h
@@ -17,12 +17,16 @@
#define WINDOWS_UTILS_H
#define WIN32_LEAN_AND_MEAN
#define HAVE_STRUCT_TIMESPEC
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
#include <Windows.h>
#include <stdint.h>
#include <io.h>
#include <stdlib.h>
#include <winsock2.h>
#include <WS2tcpip.h>
+#include "dlfcn.h"
#ifndef IOVEC
#define IOVEC
@@ -152,3 +156,7 @@ int gettimeofday(struct timeval * tp, struct timezone * tzp);
((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) \
| (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
#endif
+
+#ifndef bzero
+#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
+#endif \ No newline at end of file
diff --git a/lib/src/CMakeLists.txt b/lib/src/CMakeLists.txt
index 49b735f51..f410e3d83 100644
--- a/lib/src/CMakeLists.txt
+++ b/lib/src/CMakeLists.txt
@@ -30,6 +30,11 @@ list(APPEND LIBHICN_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/util/log.c
)
+if (WIN32)
+ list(APPEND LIBHICN_SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/util/windows/dlfcn.c
+ )
+endif ()
set (COMPILER_DEFINITIONS "-DWITH_MAPME")
include(BuildMacros)
diff --git a/lib/src/util/windows/dlfcn.c b/lib/src/util/windows/dlfcn.c
new file mode 100644
index 000000000..c8173cdb0
--- /dev/null
+++ b/lib/src/util/windows/dlfcn.c
@@ -0,0 +1,65 @@
+/* dlfcn.c */
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+static struct {
+ long lasterror;
+ const char *err_rutin;
+} var = {
+ 0,
+ NULL
+};
+
+void *dlopen (const char *filename, int flags)
+{
+ HINSTANCE hInst;
+
+ hInst= LoadLibrary (filename);
+ if (hInst==NULL) {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlopen";
+ }
+ return hInst;
+}
+
+int dlclose (void *handle)
+{
+ BOOL ok;
+ int rc= 0;
+
+ ok= FreeLibrary ((HINSTANCE)handle);
+ if (! ok) {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlclose";
+ rc= -1;
+ }
+ return rc;
+}
+
+void *dlsym (void *handle, const char *name)
+{
+ FARPROC fp;
+
+ fp= GetProcAddress ((HINSTANCE)handle, name);
+ if (!fp) {
+ var.lasterror = GetLastError ();
+ var.err_rutin = "dlsym";
+ }
+ return (void *)(intptr_t)fp;
+}
+
+const char *dlerror (void)
+{
+static char errstr [88];
+
+ if (var.lasterror) {
+ sprintf (errstr, "%s error #%ld", var.err_rutin, var.lasterror);
+ return errstr;
+ } else {
+ return NULL;
+ }
+} \ No newline at end of file