Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable HAVE_STRUCT_CMSGHDR when building with mingw #1464

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ check_function_exists(random HAVE_RANDOM)
check_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)

# check for symbols
if(WIN32 AND NOT MINGW)
if(WIN32)
anyc marked this conversation as resolved.
Show resolved Hide resolved
set(HAVE_STRUCT_CMSGHDR 1)
message(STATUS "setting HAVE_STRUCT_CMSGHDR")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL QNX)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ check_function_exists(random HAVE_RANDOM)
check_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)

# check for symbols
if(WIN32 AND NOT MINGW)
if(WIN32)
set(HAVE_STRUCT_CMSGHDR 1)
message(STATUS "setting HAVE_STRUCT_CMSGHDR")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL QNX)
Expand Down
24 changes: 20 additions & 4 deletions src/coap_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ coap_mfree_endpoint(coap_endpoint_t *ep) {
}
#endif /* COAP_SERVER_SUPPORT */

#if defined(__MINGW32__)
#if(_WIN32_WINNT >= 0x0600)
#define CMSG_FIRSTHDR WSA_CMSG_FIRSTHDR
#define CMSG_NXTHDR WSA_CMSG_NXTHDR
#define CMSG_LEN WSA_CMSG_LEN
#define CMSG_SPACE WSA_CMSG_SPACE
#define cmsghdr _WSACMSGHDR
#endif /* (_WIN32_WINNT>=0x0600) */
#endif /* defined(__MINGW32__) */

#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) && !defined(RIOT_VERSION)

#if COAP_SERVER_SUPPORT
Expand Down Expand Up @@ -734,7 +744,9 @@ struct in_pktinfo {

#if defined(_WIN32)
#include <mswsock.h>
#if !defined(__MINGW32__)
#if defined(__MINGW32__)
static __thread LPFN_WSARECVMSG lpWSARecvMsg = NULL;
#else /* ! __MINGW32__ */
static __declspec(thread) LPFN_WSARECVMSG lpWSARecvMsg = NULL;
#endif /* ! __MINGW32__ */
/* Map struct WSABUF fields to their posix counterpart */
Expand Down Expand Up @@ -783,7 +795,7 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session,
bytes_written = send(sock->fd, data, datalen, 0);
#endif
} else {
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32)
DWORD dwNumberOfBytesSent = 0;
int r;
#endif /* _WIN32 && !__MINGW32__ */
Expand Down Expand Up @@ -920,7 +932,7 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session,
}
#endif /* HAVE_STRUCT_CMSGHDR */

#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32)
r = WSASendMsg(sock->fd, &mhdr, 0 /*dwFlags*/, &dwNumberOfBytesSent, NULL /*lpOverlapped*/,
NULL /*lpCompletionRoutine*/);
if (r == 0)
Expand Down Expand Up @@ -1005,7 +1017,7 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
packet->length = (size_t)len;
}
} else {
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32)
DWORD dwNumberOfBytesRecvd = 0;
int r;
#endif /* _WIN32 && !__MINGW32__ */
Expand All @@ -1016,7 +1028,11 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
struct msghdr mhdr;
struct iovec iov[1];

#if defined(__MINGW32__)
iov[0].iov_base = (char *) packet->payload;
#else
iov[0].iov_base = packet->payload;
#endif /* defined(__MINGW32__) */
iov[0].iov_len = (iov_len_t)COAP_RXBUFFER_SIZE;

memset(&mhdr, 0, sizeof(struct msghdr));
Expand Down