From 53209fc9e2b1049787fda1fafda2471965664d37 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 18 Jun 2017 20:14:45 +1000 Subject: [PATCH 01/18] Added support for mingw64 (gcc 6.3.0) --- programs/discard_server.c | 4 ++-- programs/echo_server.c | 4 ++-- programs/ekr_client.c | 2 +- programs/ekr_loop.c | 2 +- programs/ekr_loop_offload.c | 4 ++-- programs/ekr_peer.c | 6 +++--- programs/ekr_server.c | 2 +- programs/rtcweb.c | 10 +++++----- programs/tsctp.c | 4 ++-- usrsctplib/netinet/sctp_os_userspace.h | 9 +++++---- usrsctplib/netinet/sctp_pcb.c | 2 ++ usrsctplib/netinet/sctp_userspace.c | 15 +++++++++++++-- usrsctplib/user_atomic.h | 2 ++ usrsctplib/user_recv_thread.c | 13 +++++++++---- usrsctplib/user_socket.c | 14 ++++++++++---- usrsctplib/user_socketvar.h | 2 ++ 16 files changed, 62 insertions(+), 33 deletions(-) diff --git a/programs/discard_server.c b/programs/discard_server.c index e7c789ddf..69488dff8 100644 --- a/programs/discard_server.c +++ b/programs/discard_server.c @@ -98,7 +98,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - ntohl(rcv.rcv_ppid), + (unsigned int)ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); @@ -221,7 +221,7 @@ main(int argc, char *argv[]) rcv_info.rcv_sid, rcv_info.rcv_ssn, rcv_info.rcv_tsn, - ntohl(rcv_info.rcv_ppid), + (unsigned int)ntohl(rcv_info.rcv_ppid), rcv_info.rcv_context, (flags & MSG_EOR) ? 1 : 0); } else { diff --git a/programs/echo_server.c b/programs/echo_server.c index 38f1e1333..3173f289a 100644 --- a/programs/echo_server.c +++ b/programs/echo_server.c @@ -98,7 +98,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - ntohl(rcv.rcv_ppid), + (unsigned int)ntohl(rcv.rcv_ppid), rcv.rcv_context); if (flags & MSG_EOR) { struct sctp_sndinfo snd_info; @@ -236,7 +236,7 @@ main(int argc, char *argv[]) rcv_info.rcv_sid, rcv_info.rcv_ssn, rcv_info.rcv_tsn, - ntohl(rcv_info.rcv_ppid), + (unsigned int)ntohl(rcv_info.rcv_ppid), rcv_info.rcv_context, (flags & MSG_EOR) ? 1 : 0); if (flags & MSG_EOR) { diff --git a/programs/ekr_client.c b/programs/ekr_client.c index e1ed50961..dc6703c21 100644 --- a/programs/ekr_client.c +++ b/programs/ekr_client.c @@ -141,7 +141,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - ntohl(rcv.rcv_ppid), + (int)ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/ekr_loop.c b/programs/ekr_loop.c index c81a9461e..1d0ff8ca7 100644 --- a/programs/ekr_loop.c +++ b/programs/ekr_loop.c @@ -139,7 +139,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - ntohl(rcv.rcv_ppid), + (unsigned int)ntohl(rcv.rcv_ppid), rcv.rcv_context, flags); } diff --git a/programs/ekr_loop_offload.c b/programs/ekr_loop_offload.c index 1296d0f47..41c007bab 100644 --- a/programs/ekr_loop_offload.c +++ b/programs/ekr_loop_offload.c @@ -96,7 +96,7 @@ handle_packets(void *arg) usrsctp_conninput(fdp, buffer, (size_t)length, 0); } else { fprintf(stderr, "Wrong CRC32c: expected %08x received %08x\n", - ntohl(computed_crc32c), ntohl(received_crc32c)); + (unsigned int)ntohl(computed_crc32c), (unsigned int)ntohl(received_crc32c)); } } else { fprintf(stderr, "Packet too short: length %zu", (size_t)length); @@ -160,7 +160,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - ntohl(rcv.rcv_ppid), + (unsigned int)ntohl(rcv.rcv_ppid), rcv.rcv_context, flags); } diff --git a/programs/ekr_peer.c b/programs/ekr_peer.c index 7613e42da..58c92c745 100644 --- a/programs/ekr_peer.c +++ b/programs/ekr_peer.c @@ -265,7 +265,7 @@ handle_send_failed_event(struct sctp_send_failed_event *ssfe) printf("(flags = %x) ", ssfe->ssfe_flags); } printf("message with PPID = %u, SID = %d, flags: 0x%04x due to error = 0x%08x", - ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, + (unsigned int)ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, ssfe->ssfe_info.snd_flags, ssfe->ssfe_error); n = ssfe->ssfe_length - sizeof(struct sctp_send_failed_event); for (i = 0; i < n; i++) { @@ -331,7 +331,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - ntohl(rcv.rcv_ppid), + (unsigned int)ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); @@ -486,7 +486,7 @@ main(int argc, char *argv[]) perror("usrsctp_connect"); } for (;;) { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) if (gets_s(line, LINE_LENGTH) == NULL) { #else if (fgets(line, LINE_LENGTH, stdin) == NULL) { diff --git a/programs/ekr_server.c b/programs/ekr_server.c index 6f812175f..389a1112f 100644 --- a/programs/ekr_server.c +++ b/programs/ekr_server.c @@ -140,7 +140,7 @@ receive_cb(struct socket *s, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - ntohl(rcv.rcv_ppid), + (unsigned int)ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/rtcweb.c b/programs/rtcweb.c index 4b940edcc..f91d37f3b 100644 --- a/programs/rtcweb.c +++ b/programs/rtcweb.c @@ -38,8 +38,8 @@ #include #ifdef _WIN32 #define _CRT_SECURE_NO_WARNINGS -#include -#include +#include +#include #include #else #include @@ -1103,8 +1103,8 @@ handle_send_failed_event(struct sctp_send_failed_event *ssfe) if (ssfe->ssfe_flags & ~(SCTP_DATA_SENT | SCTP_DATA_UNSENT)) { printf("(flags = %x) ", ssfe->ssfe_flags); } - printf("message with PPID = %d, SID = %d, flags: 0x%04x due to error = 0x%08x", - ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, + printf("message with PPID = %u, SID = %d, flags: 0x%04x due to error = 0x%08x", + (unsigned int)ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, ssfe->ssfe_info.snd_flags, ssfe->ssfe_error); n = ssfe->ssfe_length - sizeof(struct sctp_send_failed_event); for (i = 0; i < n; i++) { @@ -1426,7 +1426,7 @@ main(int argc, char *argv[]) unlock_peer_connection(&peer_connection); for (;;) { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) if (gets_s(line, LINE_LENGTH) == NULL) { #else if (fgets(line, LINE_LENGTH, stdin) == NULL) { diff --git a/programs/tsctp.c b/programs/tsctp.c index b35fb2a0f..903c075f9 100644 --- a/programs/tsctp.c +++ b/programs/tsctp.c @@ -31,8 +31,8 @@ #include #ifdef _WIN32 -#include -#include +#include +#include #include #include #include diff --git a/usrsctplib/netinet/sctp_os_userspace.h b/usrsctplib/netinet/sctp_os_userspace.h index fd3e0d753..ff1531d8f 100755 --- a/usrsctplib/netinet/sctp_os_userspace.h +++ b/usrsctplib/netinet/sctp_os_userspace.h @@ -45,8 +45,8 @@ #include #include #include -#include -#include +#include +#include #include "user_environment.h" typedef CRITICAL_SECTION userland_mutex_t; #if WINVER < 0x0600 @@ -103,8 +103,9 @@ typedef HANDLE userland_thread_t; #define n_time unsigned __int32 #define sa_family_t unsigned __int8 #define ssize_t __int64 +#if !defined(__MINGW32__) #define __func__ __FUNCTION__ - +#endif #ifndef EWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK #endif @@ -218,7 +219,7 @@ typedef char* caddr_t; #define bzero(buf, len) memset(buf, 0, len) #define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len) -#if _MSC_VER < 1900 +#if _MSC_VER < 1900 && !defined(__MINGW64__) #define snprintf(data, size, format, ...) _snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__) #endif #define inline __inline diff --git a/usrsctplib/netinet/sctp_pcb.c b/usrsctplib/netinet/sctp_pcb.c index 6f06d35df..a2b322bc6 100755 --- a/usrsctplib/netinet/sctp_pcb.c +++ b/usrsctplib/netinet/sctp_pcb.c @@ -6813,7 +6813,9 @@ sctp_pcb_init() #endif #if defined(__Userspace__) mbuf_initialize(NULL); +#if !defined(__MINGW32__) atomic_init(); +#endif #if defined(INET) || defined(INET6) recv_thread_init(); #endif diff --git a/usrsctplib/netinet/sctp_userspace.c b/usrsctplib/netinet/sctp_userspace.c index 1c2116059..05d49972f 100755 --- a/usrsctplib/netinet/sctp_userspace.c +++ b/usrsctplib/netinet/sctp_userspace.c @@ -31,8 +31,10 @@ #include #include #include +#if !defined(__MINGW32__) #pragma comment(lib, "IPHLPAPI.lib") #endif +#endif #include #if defined(__Userspace_os_FreeBSD) #include @@ -46,6 +48,10 @@ /* Adapter to translate Unix thread start routines to Windows thread start * routines. */ +#if defined(__MINGW32__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#endif static DWORD WINAPI sctp_create_thread_adapter(void *arg) { start_routine_t start_routine = (start_routine_t)arg; @@ -61,6 +67,9 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro return GetLastError(); return 0; } +#if defined(__MINGW32__) +#pragma GCC diagnostic pop +#endif #else int sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_routine) @@ -142,8 +151,10 @@ sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af) } for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) { if (pAdapt->IfIndex == if_index) + { ret = pAdapt->Mtu; break; + } } cleanup: if (pAdapterAddrs != NULL) { @@ -205,7 +216,7 @@ Win_getifaddrs(struct ifaddrs** interfaces) goto cleanup; } /* Enumerate through each returned adapter and save its information */ - for (pAdapt = pAdapterAddrs, count; pAdapt; pAdapt = pAdapt->Next, count++) { + for (pAdapt = pAdapterAddrs, count = 0; pAdapt; pAdapt = pAdapt->Next, count++) { addr = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in)); ifa = (struct ifaddrs *)malloc(sizeof(struct ifaddrs)); if ((addr == NULL) || (ifa == NULL)) { @@ -244,7 +255,7 @@ Win_getifaddrs(struct ifaddrs** interfaces) goto cleanup; } /* Enumerate through each returned adapter and save its information */ - for (pAdapt = pAdapterAddrs, count; pAdapt; pAdapt = pAdapt->Next, count++) { + for (pAdapt = pAdapterAddrs, count = 0; pAdapt; pAdapt = pAdapt->Next, count++) { addr6 = (struct sockaddr_in6 *)malloc(sizeof(struct sockaddr_in6)); ifa = (struct ifaddrs *)malloc(sizeof(struct ifaddrs)); if ((addr6 == NULL) || (ifa == NULL)) { diff --git a/usrsctplib/user_atomic.h b/usrsctplib/user_atomic.h index b8415c604..613cb6210 100755 --- a/usrsctplib/user_atomic.h +++ b/usrsctplib/user_atomic.h @@ -78,7 +78,9 @@ } #endif #if defined(__Userspace_os_Windows) +#if !defined(__MINGW32__) static void atomic_init() {} /* empty when we are not using atomic_mtx */ +#endif #else static inline void atomic_init() {} /* empty when we are not using atomic_mtx */ #endif diff --git a/usrsctplib/user_recv_thread.c b/usrsctplib/user_recv_thread.c index 103bd9fdd..23d25408d 100755 --- a/usrsctplib/user_recv_thread.c +++ b/usrsctplib/user_recv_thread.c @@ -451,11 +451,12 @@ recv_function_raw6(void *arg) struct iovec recv_iovec[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; + int ncounter = 0; char cmsgbuf[CMSG_SPACE(sizeof (struct in6_pktinfo))]; #else WSABUF recv_iovec[MAXLEN_MBUF_CHAIN]; int nResult, m_ErrorCode; - DWORD flags; + DWORD flags, ncounter = 0; struct sockaddr_in6 from; int fromlen; GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; @@ -472,7 +473,7 @@ recv_function_raw6(void *arg) to_fill indicates this amount. */ int to_fill = MAXLEN_MBUF_CHAIN; /* iovlen is the size of each mbuf in the chain */ - int i, n, ncounter = 0; + int i, n = 0; #if !defined(SCTP_WITH_NO_CSUM) int compute_crc = 1; #endif @@ -645,7 +646,7 @@ recv_function_udp(void *arg) to_fill indicates this amount. */ int to_fill = MAXLEN_MBUF_CHAIN; /* iovlen is the size of each mbuf in the chain */ - int i, n, ncounter, offset; + int i, n, offset; int iovlen = MCLBYTES; int want_ext = (iovlen > MLEN)? 1 : 0; int want_header = 0; @@ -665,6 +666,7 @@ recv_function_udp(void *arg) struct iovec iov[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; + int ncounter; #else GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; @@ -673,6 +675,7 @@ recv_function_udp(void *arg) WSAMSG msg; int nResult, m_ErrorCode; WSACMSGHDR *cmsgptr; + DWORD ncounter; #endif sctp_userspace_set_threadname("SCTP/UDP/IP4 rcv"); @@ -857,7 +860,7 @@ recv_function_udp6(void *arg) to_fill indicates this amount. */ int to_fill = MAXLEN_MBUF_CHAIN; /* iovlen is the size of each mbuf in the chain */ - int i, n, ncounter, offset; + int i, n, offset; int iovlen = MCLBYTES; int want_ext = (iovlen > MLEN)? 1 : 0; int want_header = 0; @@ -873,6 +876,7 @@ recv_function_udp6(void *arg) struct iovec iov[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; + int ncounter; #else GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; @@ -881,6 +885,7 @@ recv_function_udp6(void *arg) WSAMSG msg; int nResult, m_ErrorCode; WSACMSGHDR *cmsgptr; + DWORD ncounter; #endif sctp_userspace_set_threadname("SCTP/UDP/IP6 rcv"); diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c index f3e348a86..061978766 100755 --- a/usrsctplib/user_socket.c +++ b/usrsctplib/user_socket.c @@ -2898,7 +2898,7 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak, struct sockaddr_in dst; #if defined (__Userspace_os_Windows) WSAMSG win_msg_hdr; - int win_sent_len; + DWORD win_sent_len; WSABUF send_iovec[MAXLEN_MBUF_CHAIN]; WSABUF winbuf; #else @@ -3053,7 +3053,7 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak, struct sockaddr_in6 dst; #if defined (__Userspace_os_Windows) WSAMSG win_msg_hdr; - int win_sent_len; + DWORD win_sent_len; WSABUF send_iovec[MAXLEN_MBUF_CHAIN]; WSABUF winbuf; #else @@ -3262,9 +3262,15 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound) #ifdef _WIN32 ftime(&tb); localtime_s(&t, &tb.time); +#if defined(__MINGW32__) + snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, + outbound ? 'O' : 'I', + t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)); +#else _snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT, outbound ? 'O' : 'I', t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)); +#endif #else gettimeofday(&tv, NULL); sec = (time_t)tv.tv_sec; @@ -3274,7 +3280,7 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound) t->tm_hour, t->tm_min, t->tm_sec, (long)tv.tv_usec); #endif pos += PREAMBLE_LENGTH; -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) strncpy_s(dump_buf + pos, strlen(HEADER) + 1, HEADER, strlen(HEADER)); #else strcpy(dump_buf + pos, HEADER); @@ -3291,7 +3297,7 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound) dump_buf[pos++] = low < 10 ? '0' + low : 'a' + (low - 10); dump_buf[pos++] = ' '; } -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__MINGW32__) strncpy_s(dump_buf + pos, strlen(TRAILER) + 1, TRAILER, strlen(TRAILER)); #else strcpy(dump_buf + pos, TRAILER); diff --git a/usrsctplib/user_socketvar.h b/usrsctplib/user_socketvar.h index ffc8270ef..00dda6cbd 100755 --- a/usrsctplib/user_socketvar.h +++ b/usrsctplib/user_socketvar.h @@ -102,7 +102,9 @@ struct uio { */ #if defined (__Userspace_os_Windows) #define AF_ROUTE 17 +#if !defined(__MINGW32__) typedef __int32 pid_t; +#endif typedef unsigned __int32 uid_t; enum sigType { SIGNAL = 0, From a5b9beb23910540f104548646f8ad9e14c8e6913 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 25 Jun 2017 13:06:35 +1000 Subject: [PATCH 02/18] Fixed mingw32/64 issue --- usrsctplib/netinet/sctp_os_userspace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usrsctplib/netinet/sctp_os_userspace.h b/usrsctplib/netinet/sctp_os_userspace.h index ff1531d8f..e6200b084 100755 --- a/usrsctplib/netinet/sctp_os_userspace.h +++ b/usrsctplib/netinet/sctp_os_userspace.h @@ -219,7 +219,7 @@ typedef char* caddr_t; #define bzero(buf, len) memset(buf, 0, len) #define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len) -#if _MSC_VER < 1900 && !defined(__MINGW64__) +#if _MSC_VER < 1900 && !defined(__MINGW32__) #define snprintf(data, size, format, ...) _snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__) #endif #define inline __inline From 7ee1669dd523092134eb74d93f97f4e503917d91 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Thu, 25 Apr 2019 11:56:11 +0200 Subject: [PATCH 03/18] be more verbose (#312) --- usrsctplib/user_recv_thread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/usrsctplib/user_recv_thread.c b/usrsctplib/user_recv_thread.c index 2753a5c25..342880695 100755 --- a/usrsctplib/user_recv_thread.c +++ b/usrsctplib/user_recv_thread.c @@ -432,6 +432,7 @@ recv_function_raw(void *arg) } /* free the array itself */ free(recvmbuf); + SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP4 rcv", __func__); return (NULL); } #endif @@ -620,6 +621,7 @@ recv_function_raw6(void *arg) } /* free the array itself */ free(recvmbuf6); + SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP6 rcv", __func__); return (NULL); } #endif @@ -826,6 +828,7 @@ recv_function_udp(void *arg) } /* free the array itself */ free(udprecvmbuf); + SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP4 rcv", __func__); return (NULL); } #endif @@ -1014,6 +1017,7 @@ recv_function_udp6(void *arg) } /* free the array itself */ free(udprecvmbuf6); + SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP6 rcv", __func__); return (NULL); } #endif From e6d4743484f184d5f8e4e4109bd7f70e46b1a0ea Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Wed, 1 May 2019 16:20:24 +0200 Subject: [PATCH 04/18] Improve and of ICMP messages on Windows. When an ICMP message is received on Windows 10 for a UDP socket, WSAECONNRESET is reported as an error. In this case, just read again. Thanks to nxrighthere for reporting the issue and helping to nail it down. This fixes #309. --- usrsctplib/user_recv_thread.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/usrsctplib/user_recv_thread.c b/usrsctplib/user_recv_thread.c index 342880695..4d73a3121 100755 --- a/usrsctplib/user_recv_thread.c +++ b/usrsctplib/user_recv_thread.c @@ -323,12 +323,10 @@ recv_function_raw(void *arg) nResult = WSARecvFrom(SCTP_BASE_VAR(userspace_rawsctp), recv_iovec, MAXLEN_MBUF_CHAIN, &ncounter, &flags, (struct sockaddr *)&from, &fromlen, NULL, NULL); if (nResult != 0) { m_ErrorCode = WSAGetLastError(); - if (m_ErrorCode == WSAETIMEDOUT) { - continue; - } if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; } + continue; } n = ncounter; #else @@ -516,10 +514,10 @@ recv_function_raw6(void *arg) } if (nResult != 0) { m_ErrorCode = WSAGetLastError(); - if (m_ErrorCode == WSAETIMEDOUT) - continue; - if (m_ErrorCode == WSAENOTSOCK || m_ErrorCode == WSAEINTR) + if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; + } + continue; } n = ncounter; #else @@ -728,12 +726,10 @@ recv_function_udp(void *arg) } if (nResult != 0) { m_ErrorCode = WSAGetLastError(); - if (m_ErrorCode == WSAETIMEDOUT) { - continue; - } if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; } + continue; } n = ncounter; #endif @@ -935,12 +931,10 @@ recv_function_udp6(void *arg) } if (nResult != 0) { m_ErrorCode = WSAGetLastError(); - if (m_ErrorCode == WSAETIMEDOUT) { - continue; - } if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; } + continue; } n = ncounter; #endif From b8e97a777727db14485d7c8f7445d464bc40ea9d Mon Sep 17 00:00:00 2001 From: Till Zimmermann Date: Thu, 16 May 2019 09:16:44 +0200 Subject: [PATCH 05/18] Fix broken links, Make URLs' protocols consistent (#315) Two Links missed leading `http(s)://` and were broken. All links to `tools.ietf.org` now consistently use https. --- Manual.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Manual.md b/Manual.md index b13ea7e76..f6e767dd2 100644 --- a/Manual.md +++ b/Manual.md @@ -4,7 +4,7 @@ SCTP is a message oriented, reliable transport protocol with direct support for Like TCP, SCTP provides reliable, connection oriented data delivery with congestion control. Unlike TCP, SCTP also provides message boundary preservation, ordered and unordered message delivery, multi-streaming and multi-homing. Detection of data corruption, loss of data and duplication of data is achieved by using checksums and sequence numbers. A selective retransmission mechanism is applied to correct loss or corruption of data. -In this manual the socket API for the SCTP User-land implementation will be described. It is based on [RFC 6458](http://tools.ietf.org/html/rfc6458). The main focus of this document is on pointing out the differences to the SCTP Sockets API. For all aspects of the sockets API that are not mentioned in this document, please refer to [RFC 6458](http://tools.ietf.org/html/rfc6458). Questions about SCTP itself can hopefully be answered by [RFC 4960](http://tools.ietf.org/html/rfc4960). +In this manual the socket API for the SCTP User-land implementation will be described. It is based on [RFC 6458](https://tools.ietf.org/html/rfc6458). The main focus of this document is on pointing out the differences to the SCTP Sockets API. For all aspects of the sockets API that are not mentioned in this document, please refer to [RFC 6458](https://tools.ietf.org/html/rfc6458). Questions about SCTP itself can hopefully be answered by [RFC 4960](https://tools.ietf.org/html/rfc4960). ## Getting Started The user-land stack has been tested on FreeBSD 10.0, Ubuntu 11.10, Windows 7, Mac OS X 10.6, and Mac OS X 10.7. The current version of the user-land stack is provided on [github](https://github.com/sctplab/usrsctp). Download the tarball and untar it in a folder of your choice. The tarball contains all the sources to build the libusrsctp, which has to be linked to the object file of an example program. In addition there are two applications in the folder `programs` that can be built and run. @@ -133,12 +133,12 @@ usrsctp_socket(int domain, void *ulp_info) ``` -The arguments taken from [RFC 6458](http://tools.ietf.org/html/rfc6458) are: +The arguments taken from [RFC 6458](https://tools.ietf.org/html/rfc6458) are: * domain: PF_INET or PF_INET6 can be used. * type: In case of a one-to-many style socket it is SOCK_SEQPACKET, in case of a one-to-one style socket it is SOCK_STREAM. For an explanation of the differences between the socket types please -refer to [RFC 6458](http://tools.ietf.org/html/rfc6458). +refer to [RFC 6458](https://tools.ietf.org/html/rfc6458). * protocol: Set IPPROTO_SCTP. In usrsctp, a callback API can be used. @@ -161,7 +161,7 @@ Thus the only difference is the absence of a return code. ## Same Functionality as RFC 6458 The following functions have the same functionality as their kernel pendants. There prototypes -are described in the following subsections. For a detailed description please refer to [RFC 6458](http://tools.ietf.org/html/rfc6458). +are described in the following subsections. For a detailed description please refer to [RFC 6458](https://tools.ietf.org/html/rfc6458). ### usrsctp_bind() @@ -237,7 +237,7 @@ usrsctp_shutdown(struct socket *so, int how) `usrsctp_shutdown()` returns 0 on success and -1 in case of an error. ## Sending and Receiving Data -Since the publication of [RFC 6458](http://tools.ietf.org/html/rfc6458) there is only one function for sending and one for receiving +Since the publication of [RFC 6458](https://tools.ietf.org/html/rfc6458) there is only one function for sending and one for receiving that is not deprecated. Therefore, only these two are described here. ### usrsctp_sendv() @@ -260,14 +260,14 @@ usrsctp_sendv(struct socket *so, * len: Length of the data. * addrs: In this version of usrsctp at most one destination address is supported. In the case of a connected socket, the parameter `addrs` can be set to NULL. * addrcnt: Number of addresses. As at most one address is supported, addrcnt is 0 if addrs is NULL and 1 otherwise. -* info: Additional information for a message is stored in `void *info`. The data types `struct sctp_sndinfo`, `struct sctp_prinfo`, and `struct sctp_sendv_spa` are supported as defined in [RFC 6458](http://tools.ietf.org/html/rfc6458). Support for `struct sctp_authinfo` is not implemented yet, therefore, errno is set EINVAL and -1 will be returned, if it is used. +* info: Additional information for a message is stored in `void *info`. The data types `struct sctp_sndinfo`, `struct sctp_prinfo`, and `struct sctp_sendv_spa` are supported as defined in [RFC 6458](https://tools.ietf.org/html/rfc6458). Support for `struct sctp_authinfo` is not implemented yet, therefore, errno is set EINVAL and -1 will be returned, if it is used. * infolen: Length of info in bytes. * infotype: Identifies the type of the information provided in info. Possible values are * SCTP_SENDV_NOINFO * SCTP_SENDV_SNDINFO * SCTP_SENDV_PRINFO - * SCTP_SENDV_SPA (For additional information please refer to [RFC 6458](http://tools.ietf.org/html/rfc6458).) -* flags: Flags as described in [RFC 6458](http://tools.ietf.org/html/rfc6458). + * SCTP_SENDV_SPA (For additional information please refer to [RFC 6458](https://tools.ietf.org/html/rfc6458).) +* flags: Flags as described in [RFC 6458](https://tools.ietf.org/html/rfc6458). `usrsctp_sendv()` returns the number of bytes sent, or -1 if an error occurred. The variable errno is then set appropriately. @@ -291,20 +291,20 @@ usrsctp_recvv(struct socket *so, * len: Length of the buffer in bytes. * from: A pointer to an address to be filled with the sender of the received message's address. * fromlen: An in/out parameter describing the from length. -* info: A pointer to the buffer to hold the attributes of the received message. The structure type of info is determined by the infotype parameter. The attributes returned in `info` have to be handled in the same way as specified in [RFC 6458](http://tools.ietf.org/html/rfc6458). +* info: A pointer to the buffer to hold the attributes of the received message. The structure type of info is determined by the infotype parameter. The attributes returned in `info` have to be handled in the same way as specified in [RFC 6458](https://tools.ietf.org/html/rfc6458). * infolen: An in/out parameter describing the size of the info buffer. * infotype: On return, `*infotype` is set to the type of the info buffer. The current defined values are * SCTP_RECVV_NOINFO * SCTP_RECVV_RCVINFO * SCTP_RECVV_NXTINFO - * SCTP_RECVV_RN (A detailed description is given in [RFC 6458](http://tools.ietf.org/html/rfc6458)) + * SCTP_RECVV_RN (A detailed description is given in [RFC 6458](https://tools.ietf.org/html/rfc6458)) * flags: A pointer to an integer to be filled with any message flags (e.g., `MSG_NOTIFICATION`). Note that this field is an in/out parameter. Options for the receive may also be passed into the value (e.g., `MSG_EOR`). Returning from the call, the flags' value will differ from its original value. `usrsctp_recvv()` returns the number of bytes received, or -1 if an error occurred. The variable errno is then set appropriately. ## Socket Options Socket options are used to change the default behavior of socket calls. -Their behavior is specified in [RFC 6458](http://tools.ietf.org/html/rfc6458). The functions to get or set them are +Their behavior is specified in [RFC 6458](https://tools.ietf.org/html/rfc6458). The functions to get or set them are ```c int @@ -375,7 +375,7 @@ SCTP_RESET_STREAMS | struct sctp_reset_streams | w SCTP_RESET_ASSOC | struct sctp_assoc_t | w SCTP_ADD_STREAMS | struct sctp_add_streams | w -Further usage details are described in [RFC 6458](tools.ietf.org/html/rfc6458), [RFC 6525](tools.ietf.org/html/rfc6525), and [draft-ietf-tsvwg-sctp-udp-encaps-03](https://tools.ietf.org/html/draft-ietf-tsvwg-sctp-udp-encaps-03) (work in progress). +Further usage details are described in [RFC 6458](https://tools.ietf.org/html/rfc6458), [RFC 6525](https://tools.ietf.org/html/rfc6525), and [draft-ietf-tsvwg-sctp-udp-encaps-03](https://tools.ietf.org/html/draft-ietf-tsvwg-sctp-udp-encaps-03) (work in progress). ## Sysctl variables @@ -563,7 +563,7 @@ The congestion control should protect the network against fast senders. Explicit congestion notifications are turned on by default. #### usrsctp_sysctl_set_sctp_default_cc_module() -This parameter sets the default algorithm for the congestion control. Default is 0, i.e. the one specified in [RFC 4960](http://tools.ietf.org/html/rfc4960). +This parameter sets the default algorithm for the congestion control. Default is 0, i.e. the one specified in [RFC 4960](https://tools.ietf.org/html/rfc4960). #### usrsctp_sysctl_set_sctp_initial_cwnd() Set the initial congestion window in MTUs. The default is 3. @@ -578,7 +578,7 @@ How many the sames it takes to try step down of cwnd. Default: 20 ## Configure AUTH and ADD-IP -An important extension of SCTP is the dynamic address reconfiguration (see [RFC 5061](http://tools.ietf.org/html/rfc5061)), also known as ADD-IP, which allows the changing of addresses during the lifetime of an association. For this feature the AUTH extension (see [RFC 4895](http://tools.ietf.org/html/rfc4895)) is necessary. +An important extension of SCTP is the dynamic address reconfiguration (see [RFC 5061](https://tools.ietf.org/html/rfc5061)), also known as ADD-IP, which allows the changing of addresses during the lifetime of an association. For this feature the AUTH extension (see [RFC 4895](https://tools.ietf.org/html/rfc4895)) is necessary. #### usrsctp_sysctl_set_sctp_auto_asconf() If SCTP Auto-ASCONF is enabled, the peer is informed automatically when a new address @@ -752,27 +752,27 @@ See https://github.com/sctplab/usrsctp/tree/master/programs #### SCTP R. Stewart:
`Stream Control Transmission Protocol`.
-[RFC 4960](http://tools.ietf.org/html/rfc4960), September 2007. +[RFC 4960](https://tools.ietf.org/html/rfc4960), September 2007. #### auth M. Tüxen, R. Stewart, P. Lei, and E. Rescorla:
`Authenticated Chunks for the Stream Control Transmission Protocol (SCTP)`.
-[RFC 4895](http://tools.ietf.org/html/rfc4895), August 2007. +[RFC 4895](https://tools.ietf.org/html/rfc4895), August 2007. #### addip R. Stewart, Q. Xie, M. Tüxen, S. Maruyama, and M. Kozuka:
`Stream Control Transmission Protocol (SCTP) Dynamic Address Reconfiguration`.
-[RFC 5061](http://tools.ietf.org/html/rfc5061), September 2007. +[RFC 5061](https://tools.ietf.org/html/rfc5061), September 2007. #### socketAPI R. Stewart, M. Tüxen, K. Poon, and V. Yasevich:
`Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)`.
-[RFC 6458](http://tools.ietf.org/html/rfc6458), Dezember 2011. +[RFC 6458](https://tools.ietf.org/html/rfc6458), Dezember 2011. #### streamReset R. Stewart, M. Tüxen, and P. Lei:
`Stream Control Transmission Protocol (SCTP) Stream Reconfiguration`.
-[RFC 6525](http://tools.ietf.org/html/rfc6525), February 2012. +[RFC 6525](https://tools.ietf.org/html/rfc6525), February 2012. #### udpencaps M. Tüxen and R. Stewart
From e8e39b5806f415f45fe0350538da15c98c3ef840 Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Sun, 19 May 2019 18:56:39 +0200 Subject: [PATCH 06/18] Backport https://svnweb.freebsd.org/base?view=revision&revision=340783 --- usrsctplib/netinet/sctp_sysctl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/usrsctplib/netinet/sctp_sysctl.c b/usrsctplib/netinet/sctp_sysctl.c index 652ef74c4..d00545271 100755 --- a/usrsctplib/netinet/sctp_sysctl.c +++ b/usrsctplib/netinet/sctp_sysctl.c @@ -34,7 +34,7 @@ #ifdef __FreeBSD__ #include -__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 326672 2017-12-07 22:19:08Z tuexen $"); +__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 340783 2018-11-22 20:49:41Z markj $"); #endif #include @@ -498,6 +498,9 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS) SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM); return (EPERM); } + memset(&xinpcb, 0, sizeof(xinpcb)); + memset(&xstcb, 0, sizeof(xstcb)); + memset(&xraddr, 0, sizeof(xraddr)); LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) { SCTP_INP_RLOCK(inp); if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) { From ab105a043662f34921880b7d89b9cc02304917b7 Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Sun, 19 May 2019 19:33:12 +0200 Subject: [PATCH 07/18] Improve input validation for the IPPROTO_SCTP level socket options SCTP_CONNECT_X and SCTP_CONNECT_X_DELAYED. --- usrsctplib/netinet/sctp_usrreq.c | 16 +++------ usrsctplib/netinet/sctputil.c | 57 ++++++++++++++------------------ usrsctplib/netinet/sctputil.h | 9 +++-- 3 files changed, 33 insertions(+), 49 deletions(-) diff --git a/usrsctplib/netinet/sctp_usrreq.c b/usrsctplib/netinet/sctp_usrreq.c index 9430d28cb..925fe090b 100755 --- a/usrsctplib/netinet/sctp_usrreq.c +++ b/usrsctplib/netinet/sctp_usrreq.c @@ -34,7 +34,7 @@ #ifdef __FreeBSD__ #include -__FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 345525 2019-03-26 08:27:00Z tuexen $"); +__FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 347975 2019-05-19 17:28:00Z tuexen $"); #endif #include @@ -1952,13 +1952,12 @@ static int sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval, size_t optsize, void *p, int delay) { - int error = 0; + int error; int creat_lock_on = 0; struct sctp_tcb *stcb = NULL; struct sockaddr *sa; unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr; uint32_t vrf_id; - int bad_addresses = 0; sctp_assoc_t *a_id; SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n"); @@ -1997,17 +1996,12 @@ sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval, totaddrp = (unsigned int *)optval; totaddr = *totaddrp; sa = (struct sockaddr *)(totaddrp + 1); - stcb = sctp_connectx_helper_find(inp, sa, &totaddr, &num_v4, &num_v6, &error, (unsigned int)(optsize - sizeof(int)), &bad_addresses); - if ((stcb != NULL) || bad_addresses) { + error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int))); + if (error != 0) { /* Already have or am bring up an association */ SCTP_ASOC_CREATE_UNLOCK(inp); creat_lock_on = 0; - if (stcb) - SCTP_TCB_UNLOCK(stcb); - if (bad_addresses == 0) { - SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); - error = EALREADY; - } + SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); goto out_now; } #ifdef INET6 diff --git a/usrsctplib/netinet/sctputil.c b/usrsctplib/netinet/sctputil.c index 4a8e944c8..a51e18814 100755 --- a/usrsctplib/netinet/sctputil.c +++ b/usrsctplib/netinet/sctputil.c @@ -34,7 +34,7 @@ #ifdef __FreeBSD__ #include -__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 346134 2019-04-11 20:39:12Z tuexen $"); +__FBSDID("$FreeBSD: head/sys/netinet/sctputil.c 347975 2019-05-19 17:28:00Z tuexen $"); #endif #include @@ -7128,31 +7128,34 @@ sctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr, return (added); } -struct sctp_tcb * +int sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, - unsigned int *totaddr, - unsigned int *num_v4, unsigned int *num_v6, int *error, - unsigned int limit, int *bad_addr) + unsigned int totaddr, + unsigned int *num_v4, unsigned int *num_v6, + unsigned int limit) { struct sockaddr *sa; - struct sctp_tcb *stcb = NULL; + struct sctp_tcb *stcb; unsigned int incr, at, i; at = 0; sa = addr; - *error = *num_v6 = *num_v4 = 0; + *num_v6 = *num_v4 = 0; /* account and validate addresses */ - for (i = 0; i < *totaddr; i++) { + if (totaddr == 0) { + return (EINVAL); + } + for (i = 0; i < totaddr; i++) { + if (at + sizeof(struct sockaddr) > limit) { + return (EINVAL); + } switch (sa->sa_family) { #ifdef INET case AF_INET: incr = (unsigned int)sizeof(struct sockaddr_in); #ifdef HAVE_SA_LEN if (sa->sa_len != incr) { - SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); - *error = EINVAL; - *bad_addr = 1; - return (NULL); + return (EINVAL); } #endif (*num_v4) += 1; @@ -7166,18 +7169,12 @@ sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, sin6 = (struct sockaddr_in6 *)sa; if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { /* Must be non-mapped for connectx */ - SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); - *error = EINVAL; - *bad_addr = 1; - return (NULL); + return (EINVAL); } incr = (unsigned int)sizeof(struct sockaddr_in6); #ifdef HAVE_SA_LEN if (sa->sa_len != incr) { - SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL); - *error = EINVAL; - *bad_addr = 1; - return (NULL); + return (EINVAL); } #endif (*num_v6) += 1; @@ -7185,29 +7182,23 @@ sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, } #endif default: - *totaddr = i; - incr = 0; - /* we are done */ - break; + return (EINVAL); } - if (i == *totaddr) { - break; + if ((at + incr) > limit) { + return (EINVAL); } SCTP_INP_INCR_REF(inp); stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL); if (stcb != NULL) { - /* Already have or am bring up an association */ - return (stcb); + SCTP_TCB_UNLOCK(stcb); + return (EALREADY); } else { SCTP_INP_DECR_REF(inp); } - if ((at + incr) > limit) { - *totaddr = i; - break; - } + at += incr; sa = (struct sockaddr *)((caddr_t)sa + incr); } - return ((struct sctp_tcb *)NULL); + return (0); } /* diff --git a/usrsctplib/netinet/sctputil.h b/usrsctplib/netinet/sctputil.h index f3a18bee8..92cb3aef9 100755 --- a/usrsctplib/netinet/sctputil.h +++ b/usrsctplib/netinet/sctputil.h @@ -34,7 +34,7 @@ #ifdef __FreeBSD__ #include -__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 345467 2019-03-24 12:13:05Z tuexen $"); +__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 347975 2019-05-19 17:28:00Z tuexen $"); #endif #ifndef _NETINET_SCTP_UTIL_H_ @@ -223,10 +223,9 @@ void sctp_handle_ootb(struct mbuf *, int, int, int sctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr, int totaddr, int *error); -struct sctp_tcb * -sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, - unsigned int *totaddr, unsigned int *num_v4, unsigned int *num_v6, - int *error, unsigned int limit, int *bad_addr); +int +sctp_connectx_helper_find(struct sctp_inpcb *, struct sockaddr *, + unsigned int, unsigned int *, unsigned int *, unsigned int); int sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); #ifdef INET6 From 8ad82a0c311c5bcc80fd5a46aa8ac2957241bdfd Mon Sep 17 00:00:00 2001 From: Michael Tuexen Date: Sun, 19 May 2019 19:58:24 +0200 Subject: [PATCH 08/18] Allow sending on demand SCTP HEARTBEATS only in the ESTABLISHED state. --- usrsctplib/netinet/sctp_usrreq.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/usrsctplib/netinet/sctp_usrreq.c b/usrsctplib/netinet/sctp_usrreq.c index 925fe090b..f6a540188 100755 --- a/usrsctplib/netinet/sctp_usrreq.c +++ b/usrsctplib/netinet/sctp_usrreq.c @@ -34,7 +34,7 @@ #ifdef __FreeBSD__ #include -__FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 347975 2019-05-19 17:28:00Z tuexen $"); +__FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 347976 2019-05-19 17:53:36Z tuexen $"); #endif #include @@ -6164,10 +6164,11 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, net->dest_state &= ~SCTP_ADDR_NOHB; } if (paddrp->spp_flags & SPP_HB_DEMAND) { - /* on demand HB */ - sctp_send_hb(stcb, net, SCTP_SO_LOCKED); - sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED); - sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); + if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) { + sctp_send_hb(stcb, net, SCTP_SO_LOCKED); + sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED); + sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); + } } if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && (paddrp->spp_pathmtu >= SCTP_SMALLEST_PMTU)) { if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { From 2672aab44027907ec1f3a0d7a29f86fbea19489c Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 26 Jun 2019 11:27:06 +0300 Subject: [PATCH 09/18] Fix cross-build linux->mingw (#320) --- usrsctplib/netinet/sctp_os_userspace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usrsctplib/netinet/sctp_os_userspace.h b/usrsctplib/netinet/sctp_os_userspace.h index a97b51583..765deed2d 100755 --- a/usrsctplib/netinet/sctp_os_userspace.h +++ b/usrsctplib/netinet/sctp_os_userspace.h @@ -47,8 +47,8 @@ #include #include #include -#include -#include +#include +#include #include "user_environment.h" typedef CRITICAL_SECTION userland_mutex_t; #if WINVER < 0x0600 From 8e6a666c291cbd8b28664a241795065cc14238f9 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Thu, 27 Jun 2019 12:12:51 +0200 Subject: [PATCH 10/18] Fix compile error due to merge mistake. --- usrsctplib/user_recv_thread.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/usrsctplib/user_recv_thread.c b/usrsctplib/user_recv_thread.c index 8fb88a648..e78bc4a94 100755 --- a/usrsctplib/user_recv_thread.c +++ b/usrsctplib/user_recv_thread.c @@ -445,7 +445,6 @@ recv_function_raw6(void *arg) struct iovec recv_iovec[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; - int ncounter = 0; char cmsgbuf[CMSG_SPACE(sizeof (struct in6_pktinfo))]; #else WSABUF recv_iovec[MAXLEN_MBUF_CHAIN]; @@ -653,7 +652,6 @@ recv_function_udp(void *arg) struct iovec iov[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; - int ncounter; #else GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; @@ -851,11 +849,10 @@ recv_function_udp6(void *arg) char cmsgbuf[CMSG_SPACE(sizeof (struct in6_pktinfo))]; int compute_crc = 1; #if !defined(__Userspace_os_Windows) - unsigned int ncounter; struct iovec iov[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; - int ncounter; + unsigned int ncounter; #else GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; @@ -863,7 +860,6 @@ recv_function_udp6(void *arg) WSABUF iov[MAXLEN_MBUF_CHAIN]; WSAMSG msg; int nResult, m_ErrorCode; - DWORD ncounter; WSACMSGHDR *cmsgptr; DWORD ncounter; #endif From bbeb7d464507aed2e8f0879e9b826723aa6c6818 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Thu, 27 Jun 2019 15:06:26 +0200 Subject: [PATCH 11/18] test commit --- programs/discard_server.c | 2 +- programs/discard_server_upcall.c | 2 +- programs/echo_server_upcall.c | 2 +- programs/ekr_loop_offload.c | 3 ++- programs/programs_helper.c | 2 +- usrsctplib/CMakeLists.txt | 4 ++-- usrsctplib/netinet/sctp_cc_functions.c | 6 +++--- usrsctplib/netinet/sctp_pcb.h | 4 ++-- usrsctplib/user_environment.h | 2 +- usrsctplib/user_recv_thread.c | 4 ---- usrsctplib/user_socket.c | 8 ++++---- 11 files changed, 18 insertions(+), 21 deletions(-) diff --git a/programs/discard_server.c b/programs/discard_server.c index 765c84823..67c34419e 100644 --- a/programs/discard_server.c +++ b/programs/discard_server.c @@ -209,7 +209,7 @@ main(int argc, char *argv[]) &infolen, &infotype, &flags); if (n > 0) { if (flags & MSG_NOTIFICATION) { - printf("Notification of length %llu received.\n", (unsigned long long)n); + printf("Notification of length %"PRId64" received.\n", (unsigned long long)n); } else { if (infotype == SCTP_RECVV_RCVINFO) { printf("Msg of length %llu received from %s:%u on stream %u with SSN %u and TSN %u, PPID %u, context %u, complete %d.\n", diff --git a/programs/discard_server_upcall.c b/programs/discard_server_upcall.c index 51f50d435..bbba71129 100644 --- a/programs/discard_server_upcall.c +++ b/programs/discard_server_upcall.c @@ -121,7 +121,7 @@ handle_upcall(struct socket *sock, void *data, int flgs) return; } - printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %u, context %u.\n", + printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %lu, context %u.\n", (int)n, namebuf, port, diff --git a/programs/echo_server_upcall.c b/programs/echo_server_upcall.c index 7a594fa8b..b0710e1c1 100644 --- a/programs/echo_server_upcall.c +++ b/programs/echo_server_upcall.c @@ -123,7 +123,7 @@ handle_upcall(struct socket *sock, void *data, int flgs) return; } - printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %u, context %u.\n", + printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %lu, context %u.\n", (int)n, namebuf, port, diff --git a/programs/ekr_loop_offload.c b/programs/ekr_loop_offload.c index ef6cc6480..d993945dc 100644 --- a/programs/ekr_loop_offload.c +++ b/programs/ekr_loop_offload.c @@ -36,6 +36,7 @@ #include #include #include +#include #ifndef _WIN32 #include #include @@ -100,7 +101,7 @@ handle_packets(void *arg) (unsigned int)ntohl(computed_crc32c), (unsigned int)ntohl(received_crc32c)); } } else { - fprintf(stderr, "Packet too short: length %zu", (size_t)length); + fprintf(stderr, "Packet too short: length %"PRId64"\n", length); } } } diff --git a/programs/programs_helper.c b/programs/programs_helper.c index 0325a816e..80a524c8c 100644 --- a/programs/programs_helper.c +++ b/programs/programs_helper.c @@ -197,7 +197,7 @@ handle_send_failed_event(struct sctp_send_failed_event *ssfe) if (ssfe->ssfe_flags & ~(SCTP_DATA_SENT | SCTP_DATA_UNSENT)) { printf("(flags = %x) ", ssfe->ssfe_flags); } - printf("message with PPID = %u, SID = %u, flags: 0x%04x due to error = 0x%08x", + printf("message with PPID = %lu, SID = %u, flags: 0x%04x due to error = 0x%08x", ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, ssfe->ssfe_info.snd_flags, ssfe->ssfe_error); n = ssfe->ssfe_length - sizeof(struct sctp_send_failed_event); diff --git a/usrsctplib/CMakeLists.txt b/usrsctplib/CMakeLists.txt index 595f529c2..917b7506e 100644 --- a/usrsctplib/CMakeLists.txt +++ b/usrsctplib/CMakeLists.txt @@ -173,8 +173,8 @@ add_library(usrsctp-static STATIC ${usrsctp_sources} ${usrsctp_headers}) if (WIN32) message(STATUS "link library: ws2_32") - target_link_libraries(usrsctp ws2_32) - target_link_libraries(usrsctp-static ws2_32) + target_link_libraries(usrsctp ws2_32 Iphlpapi.lib) + target_link_libraries(usrsctp-static ws2_32 Iphlpapi.lib) endif () set_target_properties(usrsctp-static PROPERTIES OUTPUT_NAME "usrsctp") diff --git a/usrsctplib/netinet/sctp_cc_functions.c b/usrsctplib/netinet/sctp_cc_functions.c index e53e4d747..41a3c80b2 100755 --- a/usrsctplib/netinet/sctp_cc_functions.c +++ b/usrsctplib/netinet/sctp_cc_functions.c @@ -2410,7 +2410,7 @@ sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, const struct sctp_cc_functions sctp_cc_functions[] = { { -#if defined(__Windows__) || defined(__Userspace_os_Windows) +#if (defined(__Windows__) || defined(__Userspace_os_Windows)) && !defined(__MINGW32__) sctp_set_initial_cc_param, sctp_cwnd_update_after_sack, sctp_cwnd_update_exit_pf_common, @@ -2431,7 +2431,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = { #endif }, { -#if defined(__Windows__) || defined(__Userspace_os_Windows) +#if (defined(__Windows__) || defined(__Userspace_os_Windows)) && !defined(__MINGW32__) sctp_set_initial_cc_param, sctp_hs_cwnd_update_after_sack, sctp_cwnd_update_exit_pf_common, @@ -2452,7 +2452,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = { #endif }, { -#if defined(__Windows__) || defined(__Userspace_os_Windows) +#if (defined(__Windows__) || defined(__Userspace_os_Windows)) && !defined(__MINGW32__) sctp_htcp_set_initial_cc_param, sctp_htcp_cwnd_update_after_sack, sctp_cwnd_update_exit_pf_common, diff --git a/usrsctplib/netinet/sctp_pcb.h b/usrsctplib/netinet/sctp_pcb.h index 34881863f..5b8f6613a 100755 --- a/usrsctplib/netinet/sctp_pcb.h +++ b/usrsctplib/netinet/sctp_pcb.h @@ -320,7 +320,7 @@ struct sctp_base_info { #endif #endif #ifdef INET -#if defined(__Userspace_os_Windows) +#if defined(__Userspace_os_Windows) && !defined(__MINGW32__) SOCKET userspace_rawsctp; SOCKET userspace_udpsctp; #else @@ -331,7 +331,7 @@ struct sctp_base_info { userland_thread_t recvthreadudp; #endif #ifdef INET6 -#if defined(__Userspace_os_Windows) +#if defined(__Userspace_os_Windows) && !defined(__MINGW32__) SOCKET userspace_rawsctp6; SOCKET userspace_udpsctp6; #else diff --git a/usrsctplib/user_environment.h b/usrsctplib/user_environment.h index 7179f1f8f..2b40ceebd 100755 --- a/usrsctplib/user_environment.h +++ b/usrsctplib/user_environment.h @@ -62,7 +62,7 @@ extern int ipport_firstauto, ipport_lastauto; */ extern int nmbclusters; -#if !defined(_MSC_VER) +#if !defined(_MSC_VER) && !defined(__MINGW32__) #define min(a,b) ((a)>(b)?(b):(a)) #define max(a,b) ((a)>(b)?(a):(b)) #endif diff --git a/usrsctplib/user_recv_thread.c b/usrsctplib/user_recv_thread.c index e78bc4a94..ae5e517da 100755 --- a/usrsctplib/user_recv_thread.c +++ b/usrsctplib/user_recv_thread.c @@ -449,10 +449,8 @@ recv_function_raw6(void *arg) #else WSABUF recv_iovec[MAXLEN_MBUF_CHAIN]; int nResult, m_ErrorCode; - DWORD flags; DWORD ncounter = 0; struct sockaddr_in6 from; - int fromlen; GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; WSACMSGHDR *cmsgptr; @@ -494,9 +492,7 @@ recv_function_raw6(void *arg) } to_fill = 0; #if defined(__Userspace_os_Windows) - flags = 0; ncounter = 0; - fromlen = sizeof(struct sockaddr_in6); memset(&from, 0, sizeof(struct sockaddr_in6)); nResult = WSAIoctl(SCTP_BASE_VAR(userspace_rawsctp6), SIO_GET_EXTENSION_FUNCTION_POINTER, &WSARecvMsg_GUID, sizeof WSARecvMsg_GUID, diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c index d551e2a4a..db1620213 100755 --- a/usrsctplib/user_socket.c +++ b/usrsctplib/user_socket.c @@ -3138,14 +3138,14 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak, if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if (win_sent_len != send_len) { + } else if ((int) win_sent_len != send_len) { *result = WSAGetLastError(); } } if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if (win_sent_len != send_len) { + } else if ((int) win_sent_len != send_len) { *result = WSAGetLastError(); } } @@ -3292,14 +3292,14 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak, if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if (win_sent_len != send_len) { + } else if ((int) win_sent_len != send_len) { *result = WSAGetLastError(); } } if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if (win_sent_len != send_len) { + } else if ((int) win_sent_len != send_len) { *result = WSAGetLastError(); } } From ab7e62827a6a4f5a0026bb8e1a3c502b25879666 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Fri, 28 Jun 2019 12:26:41 +0200 Subject: [PATCH 12/18] Add MinGW and MinGW64 support --- programs/CMakeLists.txt | 5 +++++ programs/discard_server.c | 6 +++--- programs/discard_server_upcall.c | 4 ++-- programs/echo_server.c | 4 ++-- programs/echo_server_upcall.c | 4 ++-- programs/ekr_client.c | 2 +- programs/ekr_loop.c | 2 +- programs/ekr_loop_offload.c | 7 +++---- programs/ekr_loop_upcall.c | 2 +- programs/ekr_peer.c | 2 +- programs/ekr_server.c | 2 +- programs/programs_helper.c | 4 ++-- programs/programs_helper.h | 10 ++++++++++ programs/rtcweb.c | 8 ++++---- programs/tsctp.c | 13 +++++-------- 15 files changed, 43 insertions(+), 32 deletions(-) diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index d383c3f13..0f0ed7fb4 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -56,6 +56,11 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin") add_definitions(-D__APPLE_USE_RFC_2292) endif () +if (MSYS) + message(STATUS "MSYS") + add_definitions(-D__USE_MINGW_ANSI_STDIO) +endif () + ################################################# # MISC diff --git a/programs/discard_server.c b/programs/discard_server.c index 67c34419e..ae7cb81b7 100644 --- a/programs/discard_server.c +++ b/programs/discard_server.c @@ -105,7 +105,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (unsigned int)ntohl(rcv.rcv_ppid), + (uint32_t) ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); @@ -209,7 +209,7 @@ main(int argc, char *argv[]) &infolen, &infotype, &flags); if (n > 0) { if (flags & MSG_NOTIFICATION) { - printf("Notification of length %"PRId64" received.\n", (unsigned long long)n); + printf("Notification of length %llu received.\n", (unsigned long long)n); } else { if (infotype == SCTP_RECVV_RCVINFO) { printf("Msg of length %llu received from %s:%u on stream %u with SSN %u and TSN %u, PPID %u, context %u, complete %d.\n", @@ -218,7 +218,7 @@ main(int argc, char *argv[]) rcv_info.rcv_sid, rcv_info.rcv_ssn, rcv_info.rcv_tsn, - (unsigned int)ntohl(rcv_info.rcv_ppid), + (uint32_t) ntohl(rcv_info.rcv_ppid), rcv_info.rcv_context, (flags & MSG_EOR) ? 1 : 0); } else { diff --git a/programs/discard_server_upcall.c b/programs/discard_server_upcall.c index bbba71129..99a1c9a95 100644 --- a/programs/discard_server_upcall.c +++ b/programs/discard_server_upcall.c @@ -121,14 +121,14 @@ handle_upcall(struct socket *sock, void *data, int flgs) return; } - printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %lu, context %u.\n", + printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %u, context %u.\n", (int)n, namebuf, port, rn.recvv_rcvinfo.rcv_sid, rn.recvv_rcvinfo.rcv_ssn, rn.recvv_rcvinfo.rcv_tsn, - ntohl(rn.recvv_rcvinfo.rcv_ppid), + (uint32_t) ntohl(rn.recvv_rcvinfo.rcv_ppid), rn.recvv_rcvinfo.rcv_context); } } diff --git a/programs/echo_server.c b/programs/echo_server.c index 4cdd16583..a87a49ede 100644 --- a/programs/echo_server.c +++ b/programs/echo_server.c @@ -105,7 +105,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (unsigned int)ntohl(rcv.rcv_ppid), + (uint32_t) ntohl(rcv.rcv_ppid), rcv.rcv_context); if (flags & MSG_EOR) { struct sctp_sndinfo snd_info; @@ -233,7 +233,7 @@ main(int argc, char *argv[]) rcv_info.rcv_sid, rcv_info.rcv_ssn, rcv_info.rcv_tsn, - (unsigned int)ntohl(rcv_info.rcv_ppid), + (uint32_t) ntohl(rcv_info.rcv_ppid), rcv_info.rcv_context, (flags & MSG_EOR) ? 1 : 0); if (flags & MSG_EOR) { diff --git a/programs/echo_server_upcall.c b/programs/echo_server_upcall.c index b0710e1c1..f4fa125af 100644 --- a/programs/echo_server_upcall.c +++ b/programs/echo_server_upcall.c @@ -123,14 +123,14 @@ handle_upcall(struct socket *sock, void *data, int flgs) return; } - printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %lu, context %u.\n", + printf("Msg of length %d received from %s:%u on stream %d with SSN %u and TSN %u, PPID %u, context %u.\n", (int)n, namebuf, port, rn.recvv_rcvinfo.rcv_sid, rn.recvv_rcvinfo.rcv_ssn, rn.recvv_rcvinfo.rcv_tsn, - ntohl(rn.recvv_rcvinfo.rcv_ppid), + (uint32_t)ntohl(rn.recvv_rcvinfo.rcv_ppid), rn.recvv_rcvinfo.rcv_context); if (flags & MSG_EOR) { struct sctp_sndinfo snd_info; diff --git a/programs/ekr_client.c b/programs/ekr_client.c index 217802234..e249c5e4d 100644 --- a/programs/ekr_client.c +++ b/programs/ekr_client.c @@ -142,7 +142,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (int)ntohl(rcv.rcv_ppid), + (uint32_t) ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/ekr_loop.c b/programs/ekr_loop.c index c50a38621..8585de4dc 100644 --- a/programs/ekr_loop.c +++ b/programs/ekr_loop.c @@ -140,7 +140,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (unsigned int)ntohl(rcv.rcv_ppid), + (uint32_t) ntohl(rcv.rcv_ppid), rcv.rcv_context, flags); } diff --git a/programs/ekr_loop_offload.c b/programs/ekr_loop_offload.c index d993945dc..6b7a155db 100644 --- a/programs/ekr_loop_offload.c +++ b/programs/ekr_loop_offload.c @@ -36,7 +36,6 @@ #include #include #include -#include #ifndef _WIN32 #include #include @@ -98,10 +97,10 @@ handle_packets(void *arg) usrsctp_conninput(fdp, buffer, (size_t)length, 0); } else { fprintf(stderr, "Wrong CRC32c: expected %08x received %08x\n", - (unsigned int)ntohl(computed_crc32c), (unsigned int)ntohl(received_crc32c)); + (uint32_t) ntohl(computed_crc32c), (uint32_t) ntohl(received_crc32c)); } } else { - fprintf(stderr, "Packet too short: length %"PRId64"\n", length); + fprintf(stderr, "Packet too short: length %zu", (size_t)length); } } } @@ -162,7 +161,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (unsigned int)ntohl(rcv.rcv_ppid), + (uint32_t) ntohl(rcv.rcv_ppid), rcv.rcv_context, flags); } diff --git a/programs/ekr_loop_upcall.c b/programs/ekr_loop_upcall.c index 7b384916d..8cdb2ccc4 100644 --- a/programs/ekr_loop_upcall.c +++ b/programs/ekr_loop_upcall.c @@ -172,7 +172,7 @@ handle_upcall(struct socket *sock, void *data, int flgs) rn.recvv_rcvinfo.rcv_sid, rn.recvv_rcvinfo.rcv_ssn, rn.recvv_rcvinfo.rcv_tsn, - ntohl(rn.recvv_rcvinfo.rcv_ppid), + (uint32_t) ntohl(rn.recvv_rcvinfo.rcv_ppid), rn.recvv_rcvinfo.rcv_context, flags); } diff --git a/programs/ekr_peer.c b/programs/ekr_peer.c index df81dc649..7ef1a2362 100644 --- a/programs/ekr_peer.c +++ b/programs/ekr_peer.c @@ -132,7 +132,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (unsigned int)ntohl(rcv.rcv_ppid), + (uint32_t) ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/ekr_server.c b/programs/ekr_server.c index d609c4087..5906a23d5 100644 --- a/programs/ekr_server.c +++ b/programs/ekr_server.c @@ -143,7 +143,7 @@ receive_cb(struct socket *s, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (unsigned int)ntohl(rcv.rcv_ppid), + (uint32_t) ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/programs_helper.c b/programs/programs_helper.c index 80a524c8c..e7cf06a9f 100644 --- a/programs/programs_helper.c +++ b/programs/programs_helper.c @@ -197,8 +197,8 @@ handle_send_failed_event(struct sctp_send_failed_event *ssfe) if (ssfe->ssfe_flags & ~(SCTP_DATA_SENT | SCTP_DATA_UNSENT)) { printf("(flags = %x) ", ssfe->ssfe_flags); } - printf("message with PPID = %lu, SID = %u, flags: 0x%04x due to error = 0x%08x", - ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, + printf("message with PPID = %u, SID = %u, flags: 0x%04x due to error = 0x%08x", + (uint32_t) ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, ssfe->ssfe_info.snd_flags, ssfe->ssfe_error); n = ssfe->ssfe_length - sizeof(struct sctp_send_failed_event); for (i = 0; i < n; i++) { diff --git a/programs/programs_helper.h b/programs/programs_helper.h index 343cbabae..e6b45bfde 100644 --- a/programs/programs_helper.h +++ b/programs/programs_helper.h @@ -28,6 +28,16 @@ #ifndef __PROGRAMS_HELPER_H__ #define __PROGRAMS_HELPER_H__ +#ifdef _WIN32 +# ifdef _WIN64 +# define PRI_SIZET PRIu64 +# else +# define PRI_SIZET PRIu32 +# endif +#else +# define PRI_SIZET "zu" +#endif + void debug_printf(const char *format, ...); void handle_notification(union sctp_notification *notif, size_t n); #ifndef timersub diff --git a/programs/rtcweb.c b/programs/rtcweb.c index ba14b4912..599f679d6 100644 --- a/programs/rtcweb.c +++ b/programs/rtcweb.c @@ -120,10 +120,10 @@ struct peer_connection { #define SCTP_PACKED #endif -#if defined(_WIN32) +#if defined(_WIN32) && !defined(__MINGW32__) #pragma warning( push ) #pragma warning( disable : 4200 ) -#endif //defined(_WIN32) +#endif // defined(_WIN32) && !defined(__MINGW32__) struct rtcweb_datachannel_open_request { uint8_t msg_type; /* DATA_CHANNEL_OPEN_REQUEST */ uint8_t channel_type; @@ -132,9 +132,9 @@ struct rtcweb_datachannel_open_request { int16_t priority; char label[]; } SCTP_PACKED; -#if defined(_WIN32) +#if defined(_WIN32) && !defined(__MINGW32__) #pragma warning( pop ) -#endif //defined(_WIN32) +#endif // defined(_WIN32) && !defined(__MINGW32__) struct rtcweb_datachannel_open_response { uint8_t msg_type; /* DATA_CHANNEL_OPEN_RESPONSE */ diff --git a/programs/tsctp.c b/programs/tsctp.c index 8068c1ad0..5f3cfe894 100644 --- a/programs/tsctp.c +++ b/programs/tsctp.c @@ -127,9 +127,8 @@ handle_connection(void *arg) { ssize_t n; char *buf; -#ifdef _WIN32 - HANDLE tid; -#else + +#if !defined(_WIN32) pthread_t tid; #endif struct socket *conn_sock; @@ -151,9 +150,8 @@ handle_connection(void *arg) unsigned long long sum = 0; conn_sock = *(struct socket **)arg; -#ifdef _WIN32 - tid = GetCurrentThread(); -#else + +#if !defined(_WIN32) tid = pthread_self(); pthread_detach(tid); #endif @@ -349,7 +347,6 @@ int main(int argc, char **argv) unsigned long messages = 0; #ifdef _WIN32 unsigned long srcAddr; - HANDLE tid; #else in_addr_t srcAddr; pthread_t tid; @@ -648,7 +645,7 @@ int main(int argc, char **argv) continue; } #ifdef _WIN32 - tid = CreateThread(NULL, 0, &handle_connection, (void *)conn_sock, 0, NULL); + CreateThread(NULL, 0, &handle_connection, (void *)conn_sock, 0, NULL); #else pthread_create(&tid, NULL, &handle_connection, (void *)conn_sock); #endif From b8a1318f203b9be3fbfb56f08e6743e55755da18 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Fri, 28 Jun 2019 14:46:24 +0200 Subject: [PATCH 13/18] MinGW support, polishing --- programs/client_upcall.c | 20 ++++++++++---------- programs/programs_helper.h | 10 ---------- programs/rtcweb.c | 2 +- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/programs/client_upcall.c b/programs/client_upcall.c index d77b4af85..303dd54d1 100644 --- a/programs/client_upcall.c +++ b/programs/client_upcall.c @@ -66,17 +66,17 @@ typedef char* caddr_t; int inputAvailable(void) { - struct timeval tv; - fd_set fds; - tv.tv_sec = 0; - tv.tv_usec = 0; - FD_ZERO(&fds); -#ifndef _WIN32 - FD_SET(STDIN_FILENO, &fds); - select(STDIN_FILENO+1, &fds, NULL, NULL, &tv); + struct timeval tv; + fd_set fds; + tv.tv_sec = 0; + tv.tv_usec = 0; + FD_ZERO(&fds); +#if defined(_WIN32) && !defined(__MINGW32__) + FD_SET(_fileno(stdin), &fds); + select(_fileno(stdin) + 1, &fds, NULL, NULL, &tv); #else - FD_SET(_fileno(stdin), &fds); - select(_fileno(stdin) + 1, &fds, NULL, NULL, &tv); + FD_SET(STDIN_FILENO, &fds); + select(STDIN_FILENO+1, &fds, NULL, NULL, &tv); #endif return (FD_ISSET(0, &fds)); } diff --git a/programs/programs_helper.h b/programs/programs_helper.h index e6b45bfde..343cbabae 100644 --- a/programs/programs_helper.h +++ b/programs/programs_helper.h @@ -28,16 +28,6 @@ #ifndef __PROGRAMS_HELPER_H__ #define __PROGRAMS_HELPER_H__ -#ifdef _WIN32 -# ifdef _WIN64 -# define PRI_SIZET PRIu64 -# else -# define PRI_SIZET PRIu32 -# endif -#else -# define PRI_SIZET "zu" -#endif - void debug_printf(const char *format, ...); void handle_notification(union sctp_notification *notif, size_t n); #ifndef timersub diff --git a/programs/rtcweb.c b/programs/rtcweb.c index 599f679d6..4977bee1c 100644 --- a/programs/rtcweb.c +++ b/programs/rtcweb.c @@ -1120,7 +1120,7 @@ handle_send_failed_event(struct sctp_send_failed_event *ssfe) printf("(flags = %x) ", ssfe->ssfe_flags); } printf("message with PPID = %u, SID = %d, flags: 0x%04x due to error = 0x%08x", - (unsigned int)ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, + (uint32_t) ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, ssfe->ssfe_info.snd_flags, ssfe->ssfe_error); n = ssfe->ssfe_length - sizeof(struct sctp_send_failed_event); for (i = 0; i < n; i++) { From d92bca9dc63862e83b00c1a825498048dbbaa8de Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Fri, 28 Jun 2019 16:08:45 +0200 Subject: [PATCH 14/18] Sanitize non C-style comments --- programs/client_upcall.c | 4 ++-- programs/ekr_loop.c | 6 +++--- programs/ekr_loop_offload.c | 4 ++-- programs/ekr_loop_upcall.c | 7 +++---- programs/http_client_upcall.c | 2 +- programs/programs_helper.h | 2 +- programs/rtcweb.c | 4 ++-- programs/tsctp.c | 6 +++--- usrsctplib/user_mbuf.c | 2 +- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/programs/client_upcall.c b/programs/client_upcall.c index 303dd54d1..3de0783c1 100644 --- a/programs/client_upcall.c +++ b/programs/client_upcall.c @@ -40,7 +40,7 @@ #if !defined(_WIN32) #include #include -#endif // !defined(_WIN32) +#endif /* !defined(_WIN32) */ #include @@ -48,7 +48,7 @@ #include #include #include -#else // !defined(_WIN32) +#else /* !defined(_WIN32) */ #include #endif diff --git a/programs/ekr_loop.c b/programs/ekr_loop.c index 8585de4dc..cb3f59fb0 100644 --- a/programs/ekr_loop.c +++ b/programs/ekr_loop.c @@ -82,7 +82,7 @@ handle_packets(void *arg) length = recv(*fdp, buf, MAX_PACKET_SIZE, 0); if (length > 0) { if ((dump_buf = usrsctp_dumppacket(buf, (size_t)length, SCTP_DUMP_INBOUND)) != NULL) { - //fprintf(stderr, "%s", dump_buf); + /* fprintf(stderr, "%s", dump_buf); */ usrsctp_freedumpbuffer(dump_buf); } usrsctp_conninput(fdp, buf, (size_t)length, 0); @@ -111,7 +111,7 @@ conn_output(void *addr, void *buf, size_t length, uint8_t tos, uint8_t set_df) fdp = (int *)addr; #endif if ((dump_buf = usrsctp_dumppacket(buf, length, SCTP_DUMP_OUTBOUND)) != NULL) { - //fprintf(stderr, "%s", dump_buf); + /* fprintf(stderr, "%s", dump_buf); */ usrsctp_freedumpbuffer(dump_buf); } #ifdef _WIN32 @@ -476,7 +476,7 @@ main(void) } memset(line, 'A', LINE_LENGTH); sndinfo.snd_sid = 1; - sndinfo.snd_flags = 0; //SCTP_UNORDERED; + sndinfo.snd_flags = 0; /* SCTP_UNORDERED */ sndinfo.snd_ppid = htonl(DISCARD_PPID); sndinfo.snd_context = 0; sndinfo.snd_assoc_id = 0; diff --git a/programs/ekr_loop_offload.c b/programs/ekr_loop_offload.c index 6b7a155db..5e1f125ea 100644 --- a/programs/ekr_loop_offload.c +++ b/programs/ekr_loop_offload.c @@ -84,7 +84,7 @@ handle_packets(void *arg) length = recv(*fdp, buffer, MAX_PACKET_SIZE, 0); if (length > 0) { if ((dump_buffer = usrsctp_dumppacket(buffer, (size_t)length, SCTP_DUMP_INBOUND)) != NULL) { - //fprintf(stderr, "%s", dump_buffer); + /* fprintf(stderr, "%s", dump_buffer); */ usrsctp_freedumpbuffer(dump_buffer); } if ((size_t)length >= sizeof(struct sctp_common_header)) { @@ -132,7 +132,7 @@ conn_output(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df hdr->crc32c = usrsctp_crc32c(buffer, (size_t)length); } if ((dump_buffer = usrsctp_dumppacket(buffer, length, SCTP_DUMP_OUTBOUND)) != NULL) { - //fprintf(stderr, "%s", dump_buffer); + /* fprintf(stderr, "%s", dump_buffer); */ usrsctp_freedumpbuffer(dump_buffer); } #ifdef _WIN32 diff --git a/programs/ekr_loop_upcall.c b/programs/ekr_loop_upcall.c index 8cdb2ccc4..caf443c40 100644 --- a/programs/ekr_loop_upcall.c +++ b/programs/ekr_loop_upcall.c @@ -54,7 +54,7 @@ #define MAX_PACKET_SIZE (1<<16) #define LINE_LENGTH (1<<20) #define DISCARD_PPID 39 -//#define DUMP_PKTS_TO_FILE +/* #define DUMP_PKTS_TO_FILE */ #ifdef _WIN32 static DWORD WINAPI @@ -84,7 +84,7 @@ handle_packets(void *arg) length = recv(*fdp, buf, MAX_PACKET_SIZE, 0); if (length > 0) { if ((dump_buf = usrsctp_dumppacket(buf, (size_t)length, SCTP_DUMP_INBOUND)) != NULL) { - //fprintf(stderr, "%s", dump_buf); + /* fprintf(stderr, "%s", dump_buf); */ usrsctp_freedumpbuffer(dump_buf); } usrsctp_conninput(fdp, buf, (size_t)length, 0); @@ -113,7 +113,7 @@ conn_output(void *addr, void *buf, size_t length, uint8_t tos, uint8_t set_df) fdp = (int *)addr; #endif if ((dump_buf = usrsctp_dumppacket(buf, length, SCTP_DUMP_OUTBOUND)) != NULL) { - //fprintf(stderr, "%s", dump_buf); + /* fprintf(stderr, "%s", dump_buf); */ usrsctp_freedumpbuffer(dump_buf); } @@ -150,7 +150,6 @@ handle_upcall(struct socket *sock, void *data, int flgs) while ((events = usrsctp_get_events(sock)) && (events & SCTP_EVENT_READ)) { struct sctp_recvv_rn rn; ssize_t n; - //struct sockaddr_storage addr; union sctp_sockstore addr; int flags = 0; socklen_t len = (socklen_t)sizeof(addr); diff --git a/programs/http_client_upcall.c b/programs/http_client_upcall.c index cb6e60eff..0220d2509 100644 --- a/programs/http_client_upcall.c +++ b/programs/http_client_upcall.c @@ -204,7 +204,7 @@ main(int argc, char *argv[]) goto out; } - //usrsctp_set_non_blocking(sock, 1); + /* usrsctp_set_non_blocking(sock, 1); */ rtoinfo.srto_assoc_id = 0; rtoinfo.srto_initial = 1000; diff --git a/programs/programs_helper.h b/programs/programs_helper.h index 343cbabae..132685a3f 100644 --- a/programs/programs_helper.h +++ b/programs/programs_helper.h @@ -42,4 +42,4 @@ void handle_notification(union sctp_notification *notif, size_t n); } while (0) #endif -#endif // __PROGRAMS_HELPER_H__ +#endif /* __PROGRAMS_HELPER_H__ */ diff --git a/programs/rtcweb.c b/programs/rtcweb.c index 4977bee1c..157eba9a4 100644 --- a/programs/rtcweb.c +++ b/programs/rtcweb.c @@ -123,7 +123,7 @@ struct peer_connection { #if defined(_WIN32) && !defined(__MINGW32__) #pragma warning( push ) #pragma warning( disable : 4200 ) -#endif // defined(_WIN32) && !defined(__MINGW32__) +#endif /* defined(_WIN32) && !defined(__MINGW32__) */ struct rtcweb_datachannel_open_request { uint8_t msg_type; /* DATA_CHANNEL_OPEN_REQUEST */ uint8_t channel_type; @@ -134,7 +134,7 @@ struct rtcweb_datachannel_open_request { } SCTP_PACKED; #if defined(_WIN32) && !defined(__MINGW32__) #pragma warning( pop ) -#endif // defined(_WIN32) && !defined(__MINGW32__) +#endif /* defined(_WIN32) && !defined(__MINGW32__) */ struct rtcweb_datachannel_open_response { uint8_t msg_type; /* DATA_CHANNEL_OPEN_RESPONSE */ diff --git a/programs/tsctp.c b/programs/tsctp.c index 5f3cfe894..d7c23e401 100644 --- a/programs/tsctp.c +++ b/programs/tsctp.c @@ -651,13 +651,13 @@ int main(int argc, char **argv) #endif } if (verbose) { - // const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) - //inet_ntoa(remote_addr.sin_addr) + /* const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) + inet_ntoa(remote_addr.sin_addr) */ char addrbuf[INET_ADDRSTRLEN]; printf("Connection accepted from %s:%d\n", inet_ntop(AF_INET, &(remote_addr.sin_addr), addrbuf, INET_ADDRSTRLEN), ntohs(remote_addr.sin_port)); } } - //usrsctp_close(psock); // unreachable + /* usrsctp_close(psock); unreachable */ } else { memset(&encaps, 0, sizeof(struct sctp_udpencaps)); encaps.sue_address.ss_family = AF_INET; diff --git a/usrsctplib/user_mbuf.c b/usrsctplib/user_mbuf.c index d9f5a5cbf..a5037249d 100755 --- a/usrsctplib/user_mbuf.c +++ b/usrsctplib/user_mbuf.c @@ -313,7 +313,7 @@ m_getm2(struct mbuf *m, int len, int how, short type, int flags, int allonebuf) mb = m_gethdr(how, type); MCLGET(mb, how); size = MCLBYTES; - //SCTP_BUF_LEN(mb) = MCLBYTES; + /* SCTP_BUF_LEN(mb) = MCLBYTES; */ } else if (flags & M_PKTHDR) { mb = m_gethdr(how, type); if (len < MHLEN) { From 1ceeca9df868005f355054e7b86075b25bab4987 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Fri, 28 Jun 2019 16:29:16 +0200 Subject: [PATCH 15/18] Revert uint32_t casting for htonl --- programs/discard_server.c | 4 ++-- programs/discard_server_upcall.c | 2 +- programs/echo_server.c | 4 ++-- programs/echo_server_upcall.c | 2 +- programs/ekr_client.c | 2 +- programs/ekr_loop.c | 2 +- programs/ekr_loop_offload.c | 4 ++-- programs/ekr_loop_upcall.c | 2 +- programs/ekr_peer.c | 2 +- programs/ekr_server.c | 2 +- programs/programs_helper.c | 2 +- programs/rtcweb.c | 4 ++-- usrsctplib/user_socket.c | 4 ++-- 13 files changed, 18 insertions(+), 18 deletions(-) diff --git a/programs/discard_server.c b/programs/discard_server.c index ae7cb81b7..d26d2b51c 100644 --- a/programs/discard_server.c +++ b/programs/discard_server.c @@ -105,7 +105,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (uint32_t) ntohl(rcv.rcv_ppid), + ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); @@ -218,7 +218,7 @@ main(int argc, char *argv[]) rcv_info.rcv_sid, rcv_info.rcv_ssn, rcv_info.rcv_tsn, - (uint32_t) ntohl(rcv_info.rcv_ppid), + ntohl(rcv_info.rcv_ppid), rcv_info.rcv_context, (flags & MSG_EOR) ? 1 : 0); } else { diff --git a/programs/discard_server_upcall.c b/programs/discard_server_upcall.c index 99a1c9a95..51f50d435 100644 --- a/programs/discard_server_upcall.c +++ b/programs/discard_server_upcall.c @@ -128,7 +128,7 @@ handle_upcall(struct socket *sock, void *data, int flgs) rn.recvv_rcvinfo.rcv_sid, rn.recvv_rcvinfo.rcv_ssn, rn.recvv_rcvinfo.rcv_tsn, - (uint32_t) ntohl(rn.recvv_rcvinfo.rcv_ppid), + ntohl(rn.recvv_rcvinfo.rcv_ppid), rn.recvv_rcvinfo.rcv_context); } } diff --git a/programs/echo_server.c b/programs/echo_server.c index a87a49ede..583a3086f 100644 --- a/programs/echo_server.c +++ b/programs/echo_server.c @@ -105,7 +105,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (uint32_t) ntohl(rcv.rcv_ppid), + ntohl(rcv.rcv_ppid), rcv.rcv_context); if (flags & MSG_EOR) { struct sctp_sndinfo snd_info; @@ -233,7 +233,7 @@ main(int argc, char *argv[]) rcv_info.rcv_sid, rcv_info.rcv_ssn, rcv_info.rcv_tsn, - (uint32_t) ntohl(rcv_info.rcv_ppid), + ntohl(rcv_info.rcv_ppid), rcv_info.rcv_context, (flags & MSG_EOR) ? 1 : 0); if (flags & MSG_EOR) { diff --git a/programs/echo_server_upcall.c b/programs/echo_server_upcall.c index f4fa125af..7a594fa8b 100644 --- a/programs/echo_server_upcall.c +++ b/programs/echo_server_upcall.c @@ -130,7 +130,7 @@ handle_upcall(struct socket *sock, void *data, int flgs) rn.recvv_rcvinfo.rcv_sid, rn.recvv_rcvinfo.rcv_ssn, rn.recvv_rcvinfo.rcv_tsn, - (uint32_t)ntohl(rn.recvv_rcvinfo.rcv_ppid), + ntohl(rn.recvv_rcvinfo.rcv_ppid), rn.recvv_rcvinfo.rcv_context); if (flags & MSG_EOR) { struct sctp_sndinfo snd_info; diff --git a/programs/ekr_client.c b/programs/ekr_client.c index e249c5e4d..af0b834f6 100644 --- a/programs/ekr_client.c +++ b/programs/ekr_client.c @@ -142,7 +142,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (uint32_t) ntohl(rcv.rcv_ppid), + ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/ekr_loop.c b/programs/ekr_loop.c index cb3f59fb0..5988450b8 100644 --- a/programs/ekr_loop.c +++ b/programs/ekr_loop.c @@ -140,7 +140,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (uint32_t) ntohl(rcv.rcv_ppid), + ntohl(rcv.rcv_ppid), rcv.rcv_context, flags); } diff --git a/programs/ekr_loop_offload.c b/programs/ekr_loop_offload.c index 5e1f125ea..a0308c5c9 100644 --- a/programs/ekr_loop_offload.c +++ b/programs/ekr_loop_offload.c @@ -97,7 +97,7 @@ handle_packets(void *arg) usrsctp_conninput(fdp, buffer, (size_t)length, 0); } else { fprintf(stderr, "Wrong CRC32c: expected %08x received %08x\n", - (uint32_t) ntohl(computed_crc32c), (uint32_t) ntohl(received_crc32c)); + ntohl(computed_crc32c), ntohl(received_crc32c)); } } else { fprintf(stderr, "Packet too short: length %zu", (size_t)length); @@ -161,7 +161,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (uint32_t) ntohl(rcv.rcv_ppid), + ntohl(rcv.rcv_ppid), rcv.rcv_context, flags); } diff --git a/programs/ekr_loop_upcall.c b/programs/ekr_loop_upcall.c index caf443c40..c5af5f3b9 100644 --- a/programs/ekr_loop_upcall.c +++ b/programs/ekr_loop_upcall.c @@ -171,7 +171,7 @@ handle_upcall(struct socket *sock, void *data, int flgs) rn.recvv_rcvinfo.rcv_sid, rn.recvv_rcvinfo.rcv_ssn, rn.recvv_rcvinfo.rcv_tsn, - (uint32_t) ntohl(rn.recvv_rcvinfo.rcv_ppid), + ntohl(rn.recvv_rcvinfo.rcv_ppid), rn.recvv_rcvinfo.rcv_context, flags); } diff --git a/programs/ekr_peer.c b/programs/ekr_peer.c index 7ef1a2362..d51568c74 100644 --- a/programs/ekr_peer.c +++ b/programs/ekr_peer.c @@ -132,7 +132,7 @@ receive_cb(struct socket *sock, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (uint32_t) ntohl(rcv.rcv_ppid), + ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/ekr_server.c b/programs/ekr_server.c index 5906a23d5..187d8d779 100644 --- a/programs/ekr_server.c +++ b/programs/ekr_server.c @@ -143,7 +143,7 @@ receive_cb(struct socket *s, union sctp_sockstore addr, void *data, rcv.rcv_sid, rcv.rcv_ssn, rcv.rcv_tsn, - (uint32_t) ntohl(rcv.rcv_ppid), + ntohl(rcv.rcv_ppid), rcv.rcv_context); } free(data); diff --git a/programs/programs_helper.c b/programs/programs_helper.c index e7cf06a9f..0325a816e 100644 --- a/programs/programs_helper.c +++ b/programs/programs_helper.c @@ -198,7 +198,7 @@ handle_send_failed_event(struct sctp_send_failed_event *ssfe) printf("(flags = %x) ", ssfe->ssfe_flags); } printf("message with PPID = %u, SID = %u, flags: 0x%04x due to error = 0x%08x", - (uint32_t) ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, + ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, ssfe->ssfe_info.snd_flags, ssfe->ssfe_error); n = ssfe->ssfe_length - sizeof(struct sctp_send_failed_event); for (i = 0; i < n; i++) { diff --git a/programs/rtcweb.c b/programs/rtcweb.c index 157eba9a4..01470ad4a 100644 --- a/programs/rtcweb.c +++ b/programs/rtcweb.c @@ -1119,8 +1119,8 @@ handle_send_failed_event(struct sctp_send_failed_event *ssfe) if (ssfe->ssfe_flags & ~(SCTP_DATA_SENT | SCTP_DATA_UNSENT)) { printf("(flags = %x) ", ssfe->ssfe_flags); } - printf("message with PPID = %u, SID = %d, flags: 0x%04x due to error = 0x%08x", - (uint32_t) ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, + printf("message with PPID = %u, SID = %u, flags: 0x%04x due to error = 0x%08x", + ntohl(ssfe->ssfe_info.snd_ppid), ssfe->ssfe_info.snd_sid, ssfe->ssfe_info.snd_flags, ssfe->ssfe_error); n = ssfe->ssfe_length - sizeof(struct sctp_send_failed_event); for (i = 0; i < n; i++) { diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c index db1620213..c0311b969 100755 --- a/usrsctplib/user_socket.c +++ b/usrsctplib/user_socket.c @@ -3138,14 +3138,14 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak, if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if ((int) win_sent_len != send_len) { + } else if ((int)win_sent_len != send_len) { *result = WSAGetLastError(); } } if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if ((int) win_sent_len != send_len) { + } else if ((int)win_sent_len != send_len) { *result = WSAGetLastError(); } } From 111e0caa5911833ef223df0ec92546582c8d83c7 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Fri, 28 Jun 2019 16:46:26 +0200 Subject: [PATCH 16/18] Ignore wformat errors on GCC + MinGW platforms --- programs/CMakeLists.txt | 6 ++++++ usrsctplib/user_socket.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index 0f0ed7fb4..8cdff313e 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -59,6 +59,12 @@ endif () if (MSYS) message(STATUS "MSYS") add_definitions(-D__USE_MINGW_ANSI_STDIO) + + if (CMAKE_C_COMPILER_ID MATCHES "GNU") + message(STATUS "MYSYS + GCC") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format") + endif () endif () diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c index c0311b969..6ac0af7ea 100755 --- a/usrsctplib/user_socket.c +++ b/usrsctplib/user_socket.c @@ -3292,14 +3292,14 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak, if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if ((int) win_sent_len != send_len) { + } else if ((int)win_sent_len != send_len) { *result = WSAGetLastError(); } } if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) { if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { *result = WSAGetLastError(); - } else if ((int) win_sent_len != send_len) { + } else if ((int)win_sent_len != send_len) { *result = WSAGetLastError(); } } From cc4fd05bdd8c867cfddf12c473eba442660c98f1 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Mon, 29 Jul 2019 15:39:46 +0200 Subject: [PATCH 17/18] Fix compile errors for MinGW - Set minimum Windows Version to Windows 7 --- programs/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index 8cdff313e..faff58752 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -56,9 +56,11 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin") add_definitions(-D__APPLE_USE_RFC_2292) endif () -if (MSYS) +if (MSYS OR MINGW) message(STATUS "MSYS") add_definitions(-D__USE_MINGW_ANSI_STDIO) + add_definitions(-DWINVER=0x0601) + add_definitions(-D_WIN32_WINNT=0x0601) if (CMAKE_C_COMPILER_ID MATCHES "GNU") message(STATUS "MYSYS + GCC") From a49f277b8f54a30ce19e6363510b228d83adc884 Mon Sep 17 00:00:00 2001 From: Felix Weinrank Date: Tue, 30 Jul 2019 11:41:34 +0200 Subject: [PATCH 18/18] Addressed Michaels comments and improved verbosity --- CMakeLists.txt | 2 +- programs/CMakeLists.txt | 9 +++++---- usrsctplib/CMakeLists.txt | 2 +- usrsctplib/netinet/sctp_pcb.c | 2 -- usrsctplib/user_atomic.h | 2 -- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfe5724d7..24c135281 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # # Copyright (C) 2015-2015 Oleg Alexeenkov -# Copyright (C) 2015-2018 Felix Weinrank +# Copyright (C) 2015-2019 Felix Weinrank # # All rights reserved. # diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index faff58752..8e372660f 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -1,6 +1,6 @@ # # Copyright (C) 2015-2015 Oleg Alexeenkov -# Copyright (C) 2015-2017 Felix Weinrank +# Copyright (C) 2015-2019 Felix Weinrank # # All rights reserved. # @@ -57,13 +57,14 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin") endif () if (MSYS OR MINGW) - message(STATUS "MSYS") + message(STATUS "MSYS / MINGW") add_definitions(-D__USE_MINGW_ANSI_STDIO) + # 0x0601 = Windows 7 API add_definitions(-DWINVER=0x0601) add_definitions(-D_WIN32_WINNT=0x0601) if (CMAKE_C_COMPILER_ID MATCHES "GNU") - message(STATUS "MYSYS + GCC") + message(STATUS "MSYS / MINGW + GCC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format") endif () @@ -81,7 +82,7 @@ find_package(Threads) # PROGRAMS ################################################# -set(check_programs +list(APPEND check_programs chargen_server_upcall.c client.c client_upcall.c diff --git a/usrsctplib/CMakeLists.txt b/usrsctplib/CMakeLists.txt index 917b7506e..5e866705a 100644 --- a/usrsctplib/CMakeLists.txt +++ b/usrsctplib/CMakeLists.txt @@ -1,6 +1,6 @@ # # Copyright (C) 2015-2015 Oleg Alexeenkov -# Copyright (C) 2015-2017 Felix Weinrank +# Copyright (C) 2015-2019 Felix Weinrank # # All rights reserved. # diff --git a/usrsctplib/netinet/sctp_pcb.c b/usrsctplib/netinet/sctp_pcb.c index 549ed7cc8..4dceec5d8 100755 --- a/usrsctplib/netinet/sctp_pcb.c +++ b/usrsctplib/netinet/sctp_pcb.c @@ -6852,9 +6852,7 @@ sctp_pcb_init() #endif #if defined(__Userspace__) mbuf_initialize(NULL); -#if !defined(__MINGW32__) atomic_init(); -#endif #if defined(INET) || defined(INET6) recv_thread_init(); #endif diff --git a/usrsctplib/user_atomic.h b/usrsctplib/user_atomic.h index 2e6db0484..77ea77b67 100755 --- a/usrsctplib/user_atomic.h +++ b/usrsctplib/user_atomic.h @@ -78,9 +78,7 @@ } #endif #if defined(__Userspace_os_Windows) -#if !defined(__MINGW32__) static void atomic_init(void) {} /* empty when we are not using atomic_mtx */ -#endif #else static inline void atomic_init(void) {} /* empty when we are not using atomic_mtx */ #endif