Merge branch 'master' of github.com:sctplab/usrsctp
diff --git a/gen-def.py b/gen-def.py
new file mode 100644
index 0000000..55c0285
--- /dev/null
+++ b/gen-def.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+#
+# gen-def.py usrsctp.lib
+import re
+import sys
+import subprocess
+from shutil import which
+
+try:
+    lib_file = sys.argv[1]
+except:
+    print('Usage: gen-def.py LIB-FILE')
+    exit(-1)
+
+print('EXPORTS')
+
+if which('dumpbin'):
+    dumpbin_cmd = subprocess.run(['dumpbin', '/linkermember:1', lib_file],
+        stdout=subprocess.PIPE)
+
+    pattern = re.compile('\s*[0-9a-fA-F]+ _?(?P<functionname>usrsctp_[^\s]*)')
+
+    for line in dumpbin_cmd.stdout.decode('utf-8').splitlines():
+        match = pattern.match(line)
+        if match:
+            print(match.group('functionname'))
diff --git a/meson.build b/meson.build
index 942bbed..763edf9 100644
--- a/meson.build
+++ b/meson.build
@@ -183,11 +183,32 @@
 subdir('usrsctplib')
 
 # Build library
-usrsctp = library('usrsctp', sources,
-    dependencies: dependencies,
-    include_directories: include_dirs,
-    install: true,
-    version: meson.project_version())
+if compiler.get_id() == 'msvc' and get_option('default_library') == 'shared'
+    # Needed by usrsctp_def
+    find_program('dumpbin')
+
+    usrsctp_static = static_library('usrsctp-static', sources,
+        dependencies: dependencies,
+        include_directories: include_dirs)
+
+   usrsctp_def = custom_target('usrsctp.def',
+        command: [find_program('gen-def.py'), '@INPUT@'],
+        input: usrsctp_static,
+        output: 'usrsctp.def',
+        capture: true)
+
+    usrsctp = shared_library('usrsctp',
+        link_whole: usrsctp_static,
+        vs_module_defs: usrsctp_def,
+        install: true,
+        version: meson.project_version())
+else
+    usrsctp = library('usrsctp', sources,
+        dependencies: dependencies,
+        include_directories: include_dirs,
+        install: true,
+        version: meson.project_version())
+endif
 
 # Declare dependency
 usrsctp_dep = declare_dependency(
diff --git a/programs/chargen_server_upcall.c b/programs/chargen_server_upcall.c
index 9111a06..20c5a8f 100644
--- a/programs/chargen_server_upcall.c
+++ b/programs/chargen_server_upcall.c
@@ -167,6 +167,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((listening_socket = usrsctp_socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP, NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/client.c b/programs/client.c
index 5dac2f4..578a787 100644
--- a/programs/client.c
+++ b/programs/client.c
@@ -115,6 +115,8 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
+
 	if ((sock = usrsctp_socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP, receive_cb, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
 	}
diff --git a/programs/client_upcall.c b/programs/client_upcall.c
index 3de0783..b7b25f6 100644
--- a/programs/client_upcall.c
+++ b/programs/client_upcall.c
@@ -150,6 +150,8 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
+
 	if ((sock = usrsctp_socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP, NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
 		exit(1);
diff --git a/programs/daytime_server.c b/programs/daytime_server.c
index 38f523e..3047558 100644
--- a/programs/daytime_server.c
+++ b/programs/daytime_server.c
@@ -78,6 +78,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP, NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/daytime_server_upcall.c b/programs/daytime_server_upcall.c
index af71383..522f3f1 100644
--- a/programs/daytime_server_upcall.c
+++ b/programs/daytime_server_upcall.c
@@ -99,6 +99,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP, NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/discard_server.c b/programs/discard_server.c
index d26d2b5..5584247 100644
--- a/programs/discard_server.c
+++ b/programs/discard_server.c
@@ -147,6 +147,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_ALL);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, use_cb?receive_cb:NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/discard_server_upcall.c b/programs/discard_server_upcall.c
index 51f50d4..986a950 100644
--- a/programs/discard_server_upcall.c
+++ b/programs/discard_server_upcall.c
@@ -163,6 +163,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/echo_server.c b/programs/echo_server.c
index 583a308..4b4a3e5 100644
--- a/programs/echo_server.c
+++ b/programs/echo_server.c
@@ -162,6 +162,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, use_cb?receive_cb:NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/echo_server_upcall.c b/programs/echo_server_upcall.c
index 7a594fa..4c966cd 100644
--- a/programs/echo_server_upcall.c
+++ b/programs/echo_server_upcall.c
@@ -180,6 +180,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP, NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/http_client.c b/programs/http_client.c
index c374812..ca14c89 100644
--- a/programs/http_client.c
+++ b/programs/http_client.c
@@ -169,6 +169,7 @@
 #endif
 
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(address_family, SOCK_STREAM, IPPROTO_SCTP, receive_cb, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/http_client_upcall.c b/programs/http_client_upcall.c
index 0220d25..e2c0503 100644
--- a/programs/http_client_upcall.c
+++ b/programs/http_client_upcall.c
@@ -197,6 +197,7 @@
 #endif
 
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(address_family, SOCK_STREAM, IPPROTO_SCTP, NULL, NULL, 0, NULL)) == NULL) {
 		perror("usrsctp_socket");
diff --git a/programs/rtcweb.c b/programs/rtcweb.c
index 01470ad..720aef9 100644
--- a/programs/rtcweb.c
+++ b/programs/rtcweb.c
@@ -1336,6 +1336,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_NONE);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 
 	if ((sock = usrsctp_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP, receive_cb, NULL, 0, &peer_connection)) == NULL) {
 		perror("socket");
diff --git a/programs/tsctp.c b/programs/tsctp.c
index d7c23e4..94c2a0a 100644
--- a/programs/tsctp.c
+++ b/programs/tsctp.c
@@ -569,6 +569,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_ALL);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 	usrsctp_sysctl_set_sctp_enable_sack_immediately(1);
 
 	if (client) {
diff --git a/programs/tsctp_upcall.c b/programs/tsctp_upcall.c
index 16b589a..16676c3 100644
--- a/programs/tsctp_upcall.c
+++ b/programs/tsctp_upcall.c
@@ -627,6 +627,7 @@
 	usrsctp_sysctl_set_sctp_debug_on(SCTP_DEBUG_ALL);
 #endif
 	usrsctp_sysctl_set_sctp_blackhole(2);
+	usrsctp_sysctl_set_sctp_no_csum_on_loopback(0);
 	usrsctp_sysctl_set_sctp_enable_sack_immediately(1);
 
 	if (!(psock = usrsctp_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP, NULL, NULL, 0, NULL))) {