From 0b4e4287c9b174661d936d319b465e2a6ecf665f Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Thu, 6 Jul 2023 10:38:51 +0200 Subject: [PATCH] getsockopt needs to take in an int MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This caused an issue on big endian platforms From the getsockopt man page: Most socket-level options utilize an int argument for optval. For setsockopt(), the argument should be non‐ zero to enable a boolean option, or zero if the option is to be disabled. --- src/wolfio.c | 8 ++++---- wolfssl/wolfio.h | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/wolfio.c b/src/wolfio.c index f5bb180cd..d4408b41b 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -418,12 +418,12 @@ static int PeerIsIpv6(const SOCKADDR_S *peer, XSOCKLENT len) static int isDGramSock(int sfd) { - char type = 0; + int type = 0; /* optvalue 'type' is of size int */ - XSOCKLENT length = (XSOCKLENT)sizeof(char); + XSOCKLENT length = (XSOCKLENT)sizeof(type); - if (getsockopt(sfd, SOL_SOCKET, SO_TYPE, &type, &length) == 0 && - type != SOCK_DGRAM) { + if (getsockopt(sfd, SOL_SOCKET, SO_TYPE, (XSOCKOPT_TYPE_OPTVAL_TYPE)&type, + &length) == 0 && type != SOCK_DGRAM) { return 0; } else { diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index f783fd039..8c3238405 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -381,6 +381,13 @@ #define XSOCKLENT socklen_t #endif #endif + #ifndef XSOCKOPT_TYPE_OPTVAL_TYPE + #ifdef USE_WINDOWS_API + #define XSOCKOPT_TYPE_OPTVAL_TYPE void* + #else + #define XSOCKOPT_TYPE_OPTVAL_TYPE char* + #endif + #endif /* Socket Addr Support */ #ifdef HAVE_SOCKADDR