libipsec: Fix Windows build via MinGW
authorTobias Brunner <tobias@strongswan.org>
Fri, 23 Sep 2016 06:52:17 +0000 (08:52 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 25 Jan 2017 16:12:30 +0000 (17:12 +0100)
Fixes #2118.

scripts/test.sh
src/libipsec/Makefile.am
src/libipsec/esp_packet.c
src/libipsec/ip_packet.c
src/libstrongswan/utils/compat/windows.h

index a43d724..db24222 100755 (executable)
@@ -56,7 +56,7 @@ win*)
                        --enable-constraints --enable-revocation --enable-pem --enable-pkcs1
                        --enable-pkcs8 --enable-x509 --enable-pubkey --enable-acert
                        --enable-eap-tnc --enable-eap-ttls --enable-eap-identity
-                       --enable-updown --enable-ext-auth
+                       --enable-updown --enable-ext-auth --enable-libipsec
                        --enable-tnccs-20 --enable-imc-attestation --enable-imv-attestation
                        --enable-imc-os --enable-imv-os --enable-tnc-imv --enable-tnc-imc
                        --enable-pki --enable-swanctl --enable-socket-win"
index 90b4561..a35aba2 100644 (file)
@@ -16,6 +16,10 @@ ipsec_sa_mgr.c ipsec_sa_mgr.h
 libipsec_la_LIBADD = \
        $(top_builddir)/src/libstrongswan/libstrongswan.la
 
+if USE_WINDOWS
+  libipsec_la_LIBADD += -lws2_32
+endif
+
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/libstrongswan
 
index 50bc8b4..2c52177 100644 (file)
@@ -25,7 +25,9 @@
 #include <bio/bio_reader.h>
 #include <bio/bio_writer.h>
 
+#ifndef WIN32
 #include <netinet/in.h>
+#endif
 
 typedef struct private_esp_packet_t private_esp_packet_t;
 
index 0fdd5d3..78b4c40 100644 (file)
 #include <utils/debug.h>
 
 #include <sys/types.h>
+
+#ifndef WIN32
 #include <netinet/in.h>
 #include <netinet/ip.h>
 #ifdef HAVE_NETINET_IP6_H
 #include <netinet/ip6.h>
 #endif
+#else
+struct ip {
+#if BYTE_ORDER == LITTLE_ENDIAN
+       uint8_t ip_hl: 4;
+       uint8_t ip_v: 4;
+#elif BYTE_ORDER == BIG_ENDIAN
+       uint8_t ip_v: 4;
+       uint8_t ip_hl: 4;
+#endif
+       uint8_t ip_tos;
+       uint16_t ip_len;
+       uint16_t ip_id;
+       uint16_t ip_off;
+       uint8_t ip_ttl;
+       uint8_t ip_p;
+       uint16_t ip_sum;
+       struct in_addr ip_src, ip_dst;
+} __attribute__((packed));
+struct ip6_hdr {
+       uint32_t ip6_flow; /* 4 bit version, 8 bit TC, 20 bit flow label */
+       uint16_t ip6_plen;
+       uint8_t ip6_nxt;
+       uint8_t ip6_hlim;
+       struct in6_addr ip6_src, ip6_dst;
+} __attribute__((packed));
+#define HAVE_NETINET_IP6_H /* not really, but we only need the struct above */
+#endif
 
 /**
  * TCP header, defined here because platforms disagree regarding member names
index f7e6207..68e1dca 100644 (file)
@@ -114,6 +114,13 @@ static inline char* strdup_windows(const char *src)
 char* strndup(const char *s, size_t n);
 
 /**
+ * From winsock2.h
+ */
+#ifndef IPPROTO_IPIP
+#define IPPROTO_IPIP IPPROTO_IPV4
+#endif
+
+/**
  * Provided via ws2_32
  */
 #ifndef InetNtop