From 19735b69b847aea0b5b3a6d959584b983d76f34a Mon Sep 17 00:00:00 2001 From: gufe44 Date: Thu, 13 Aug 2020 11:03:54 +0200 Subject: [PATCH] Fix building on NetBSD 9.0 Fixes #2310 Signed-off-by: gufe44 --- ChangeLog.d/fix-build-netbsd.txt | 5 +++++ library/net_sockets.c | 9 +++++++-- programs/ssl/ssl_mail_client.c | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 ChangeLog.d/fix-build-netbsd.txt diff --git a/ChangeLog.d/fix-build-netbsd.txt b/ChangeLog.d/fix-build-netbsd.txt new file mode 100644 index 000000000..000614e37 --- /dev/null +++ b/ChangeLog.d/fix-build-netbsd.txt @@ -0,0 +1,5 @@ +Bugfix + * Fix building library/net_sockets.c and the ssl_mail_client program on + NetBSD. NetBSD conditionals were added for the backport to avoid the risk + of breaking a platform. Original fix contributed by Nia Alarie in #3422. + Adapted for long-term support branch 2.16 in #3558. diff --git a/library/net_sockets.c b/library/net_sockets.c index 9489576aa..303e5e8eb 100644 --- a/library/net_sockets.c +++ b/library/net_sockets.c @@ -51,6 +51,10 @@ * Harmless on other platforms. */ #define _POSIX_C_SOURCE 200112L +#if defined(__NetBSD__) +#define _XOPEN_SOURCE 600 /* sockaddr_storage */ +#endif + #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else @@ -345,8 +349,9 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx, struct sockaddr_storage client_addr; -#if defined(__socklen_t_defined) || defined(_SOCKLEN_T) || \ - defined(_SOCKLEN_T_DECLARED) || defined(__DEFINED_socklen_t) +#if defined(__socklen_t_defined) || defined(_SOCKLEN_T) || \ + defined(_SOCKLEN_T_DECLARED) || defined(__DEFINED_socklen_t) || \ + ( defined(__NetBSD__) && defined(socklen_t) ) socklen_t n = (socklen_t) sizeof( client_addr ); socklen_t type_len = (socklen_t) sizeof( type ); #else diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index 97d5d8ae3..b519491c7 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -51,6 +51,10 @@ * Harmless on other platforms. */ #define _POSIX_C_SOURCE 200112L +#if defined(__NetBSD__) +#define _XOPEN_SOURCE 600 +#endif + #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else