OpenBSD build fixes

Closes #3474. Thanks to Stuart Henderson
This commit is contained in:
Roger A. Light 2026-02-06 14:22:54 +00:00 committed by Roger Light
parent 5ce4f07f6a
commit 0a64c1de23
8 changed files with 38 additions and 14 deletions

View file

@ -1,3 +1,10 @@
2.1.2 - 2026-02-xx
==================
Build:
- Build fixes for OpenBSD. Closes #3474.
2.1.1 - 2026-02-04
==================

View file

@ -32,6 +32,7 @@ Contributors:
#include <time.h>
#ifndef WIN32
# include <netinet/in.h>
# include <unistd.h>
#endif

View file

@ -23,6 +23,7 @@ extern "C" {
#endif
#include <cjson/cJSON.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>

View file

@ -25,6 +25,7 @@ Contributors:
# include <ws2tcpip.h>
#else
# include <arpa/inet.h>
# include <netinet/in.h>
#endif
#include "callbacks.h"

View file

@ -21,7 +21,10 @@ Contributors:
#ifdef __APPLE__
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <sys/time.h>
#endif
#if defined(__APPLE__) || defined(__OpenBSD__)
# include <sys/time.h>
#endif
#ifdef WIN32

View file

@ -189,29 +189,38 @@ void bridge__start_all(void)
static int bridge__set_tcp_keepalive(struct mosquitto *context)
{
unsigned int idle = context->bridge->tcp_keepalive_idle;
unsigned int interval = context->bridge->tcp_keepalive_interval;
unsigned int counter = context->bridge->tcp_keepalive_counter;
unsigned int enabled = 1;
bool ret;
if(idle == 0 || interval == 0 || counter == 0){
if(context->bridge->tcp_keepalive_idle == 0
|| context->bridge->tcp_keepalive_interval == 0
|| context->bridge->tcp_keepalive_counter == 0){
return MOSQ_ERR_SUCCESS;
}
#ifdef WIN32
ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&enabled, sizeof(enabled)) ||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (char *)&idle, sizeof(idle)) ||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (char *)&interval, sizeof(interval)) ||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (char *)&counter, sizeof(counter));
# define SETSOCKOPT_TYPE char *
#else
ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (const void *)&enabled, sizeof(enabled)) ||
#ifndef __APPLE__
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE, (const void *)&idle, sizeof(idle)) ||
# define SETSOCKOPT_TYPE const void *
#endif
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL, (const void *)&interval, sizeof(interval)) ||
setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT, (const void *)&counter, sizeof(counter));
ret = setsockopt(context->sock, SOL_SOCKET, SO_KEEPALIVE, (SETSOCKOPT_TYPE)&enabled, sizeof(enabled));
#ifdef TCP_KEEPIDLE
ret = ret || setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPIDLE,
(SETSOCKOPT_TYPE)&context->bridge->tcp_keepalive_idle, sizeof(context->bridge->tcp_keepalive_idle));
#endif
#ifdef TCP_KEEPINTVL
ret = ret || setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPINTVL,
(SETSOCKOPT_TYPE)&context->bridge->tcp_keepalive_interval, sizeof(context->bridge->tcp_keepalive_interval));
#endif
#ifdef TCP_KEEPCNT
ret = ret || setsockopt(context->sock, IPPROTO_TCP, TCP_KEEPCNT,
(SETSOCKOPT_TYPE)&context->bridge->tcp_keepalive_counter, sizeof(context->bridge->tcp_keepalive_counter));
#endif
#undef SETSOCKOPT_TYPE
if(ret){
return MOSQ_ERR_UNKNOWN;

View file

@ -3,6 +3,7 @@
# include <ws2tcpip.h>
#else
# include <arpa/inet.h>
# include <netinet/in.h>
#endif
#include <stdint.h>
#include "mosquitto_broker_internal.h"

View file

@ -3,6 +3,7 @@
# include <ws2tcpip.h>
#else
# include <arpa/inet.h>
# include <netinet/in.h>
#endif
#include <stdint.h>
#include "mosquitto_broker_internal.h"