Merge pull request #5848 from philljj/fix_mingw64_build

Fix mingw-w64 build issues on windows.
This commit is contained in:
Sean Parkinson
2022-12-07 08:57:07 +10:00
committed by GitHub
7 changed files with 40 additions and 15 deletions

View File

@ -8144,8 +8144,9 @@ AX_HARDEN_CC_COMPILER_FLAGS
case $host_os in
mingw*)
# if mingw then link to ws2_32 for sockets
# if mingw then link to ws2_32 for sockets, and crypt32
LDFLAGS="$LDFLAGS -lws2_32"
LIB_ADD="$LIB_ADD -lcrypt32"
if test "$enable_shared" = "yes"
then
AC_DEFINE([WOLFSSL_DLL], [1], [Use __declspec(dllexport) when building library])

View File

@ -2144,7 +2144,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
return WOLFSSL_FAILURE;
}
b->num = sfd;
b->num = (int)sfd;
b->shutdown = BIO_CLOSE;
return WOLFSSL_SUCCESS;
}
@ -2173,7 +2173,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
WOLFSSL_ENTER("wolfIO_TcpBind error");
return WOLFSSL_FAILURE;
}
b->num = sfd;
b->num = (int)sfd;
b->shutdown = BIO_CLOSE;
}
else {

View File

@ -167,8 +167,13 @@
#ifdef _WIN32
#include <windows.h>
#include <Wincrypt.h>
/* mingw gcc does not support pragma comment, and the
* linking with crypt32 is handled in configure.ac */
#if !defined(__MINGW32__) && !defined(__MINGW64__)
#pragma comment(lib, "crypt32")
#endif
#endif
#if defined(__APPLE__) && defined(HAVE_SECURITY_SECTRUSTSETTINGS_H)
#include <Security/SecTrustSettings.h>

View File

@ -837,7 +837,7 @@ int wolfIO_Recv(SOCKET_T sd, char *buf, int sz, int rdFlags)
int recvd;
recvd = (int)RECV_FUNCTION(sd, buf, sz, rdFlags);
recvd = TranslateReturnCode(recvd, sd);
recvd = TranslateReturnCode(recvd, (int)sd);
return recvd;
}
@ -847,7 +847,7 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags)
int sent;
sent = (int)SEND_FUNCTION(sd, buf, sz, wrFlags);
sent = TranslateReturnCode(sent, sd);
sent = TranslateReturnCode(sent, (int)sd);
return sent;
}
@ -1142,6 +1142,7 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
#endif
{
WOLFSSL_MSG("bad socket fd, out of fds?");
*sockfd = SOCKET_INVALID;
return -1;
}
@ -1206,7 +1207,12 @@ int wolfIO_TcpBind(SOCKET_T* sockfd, word16 port)
sin->sin_port = XHTONS(port);
*sockfd = (SOCKET_T)socket(AF_INET, SOCK_STREAM, 0);
if (*sockfd < 0) {
#ifdef USE_WINDOWS_API
if (*sockfd == SOCKET_INVALID)
#else
if (*sockfd <= SOCKET_INVALID)
#endif
{
WOLFSSL_MSG("socket failed");
*sockfd = SOCKET_INVALID;
return -1;
@ -1794,7 +1800,7 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
WOLFSSL_MSG("OCSP ocsp request failed");
}
else {
ret = wolfIO_HttpProcessResponseOcsp(sfd, ocspRespBuf, httpBuf,
ret = wolfIO_HttpProcessResponseOcsp((int)sfd, ocspRespBuf, httpBuf,
HTTP_SCRATCH_BUFFER_SIZE, ctx);
}
if (sfd != SOCKET_INVALID)

View File

@ -36310,7 +36310,7 @@ static int test_wolfSSL_set_options(void)
WOLFSSL_OP_NO_COMPRESSION) == WOLFSSL_OP_NO_COMPRESSION);
#ifdef OPENSSL_EXTRA
AssertNull((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
AssertFalse((wolfSSL_clear_options(ssl, WOLFSSL_OP_NO_COMPRESSION) &
WOLFSSL_OP_NO_COMPRESSION));
#endif

View File

@ -451,7 +451,12 @@ void wait_tcp_ready(func_args* args)
(void)tx_mutex_put(&args->signal->mutex);
#elif defined(USE_WINDOWS_API)
/* Give peer a moment to get running */
#if defined(__MINGW32__) || defined(__MINGW64__)
Sleep(500);
#else
_sleep(500);
#endif
(void)args;
#else
(void)args;
#endif

View File

@ -358,7 +358,11 @@
#endif
#ifdef USE_WINDOWS_API
#if defined(__MINGW64__)
typedef size_t SOCKET_T;
#else
typedef unsigned int SOCKET_T;
#endif
#ifndef SOCKET_INVALID
#define SOCKET_INVALID INVALID_SOCKET
#endif
@ -745,9 +749,13 @@ WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
#define XINET_PTON(a,b,c) inet_pton((a),(b),(c))
#ifdef USE_WINDOWS_API /* Windows-friendly definition */
#undef XINET_PTON
#if defined(__MINGW64__) && !defined(UNICODE)
#define XINET_PTON(a,b,c) InetPton((a),(b),(c))
#else
#define XINET_PTON(a,b,c) InetPton((a),(PCWSTR)(b),(c))
#endif
#endif
#endif
#ifndef XHTONS
#if !defined(WOLFSSL_NO_SOCK) && (defined(USE_WOLFSSL_IO) || defined(HAVE_HTTP_CLIENT))