Skip to content

Commit 3520b4c

Browse files
authored
Merge pull request #9636 from julek-wolfssl/zephyr-fixes-202601
Address Zephyr and C++ compatibility issues
2 parents 6bdc6a7 + f9aec60 commit 3520b4c

File tree

5 files changed

+62
-12
lines changed

5 files changed

+62
-12
lines changed

wolfssl/openssl/conf.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,30 @@
2424
#ifndef WOLFSSL_conf_H_
2525
#define WOLFSSL_conf_H_
2626

27+
#include <wolfssl/wolfcrypt/settings.h>
28+
#include <wolfssl/version.h>
29+
2730
#ifdef __cplusplus
2831
extern "C" {
2932
#endif
3033

31-
#include <wolfssl/wolfcrypt/settings.h>
32-
#include <wolfssl/version.h>
33-
3434
typedef struct WOLFSSL_CONF_VALUE {
3535
char *section;
3636
char *name;
3737
char *value;
3838
} WOLFSSL_CONF_VALUE;
3939

40+
#ifdef __cplusplus
41+
} /* extern "C" */
42+
#endif
43+
4044
/* ssl.h requires WOLFSSL_CONF_VALUE */
4145
#include <wolfssl/ssl.h>
4246

47+
#ifdef __cplusplus
48+
extern "C" {
49+
#endif
50+
4351
typedef struct WOLFSSL_CONF {
4452
void *meth_data;
4553
WOLF_LHASH_OF(WOLFSSL_CONF_VALUE) *data;

wolfssl/ssl.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,21 @@ typedef struct WOLFSSL_BY_DIR WOLFSSL_BY_DIR;
270270
/* redeclare guard */
271271
#define WOLFSSL_TYPES_DEFINED
272272

273+
#ifdef __cplusplus
274+
} /* extern "C" */
275+
#endif
276+
273277
#include <wolfssl/wolfio.h>
274278

275279
/* The WOLFSSL_RSA type is required in all build configurations. */
276280
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
277281
#include <wolfssl/openssl/rsa.h>
278282
#endif
279283

284+
#ifdef __cplusplus
285+
extern "C" {
286+
#endif
287+
280288
#ifndef WC_RNG_TYPE_DEFINED /* guard on redeclaration */
281289
typedef struct WC_RNG WC_RNG;
282290
#define WC_RNG_TYPE_DEFINED
@@ -2158,12 +2166,6 @@ WOLFSSL_API int wolfSSL_BIO_set_mem_buf(WOLFSSL_BIO* bio, WOLFSSL_BUF_MEM* bufMe
21582166
#endif
21592167
WOLFSSL_API int wolfSSL_BIO_get_len(WOLFSSL_BIO *bio);
21602168

2161-
#ifdef WOLFSSL_HAVE_BIO_ADDR
2162-
WOLFSSL_API WOLFSSL_BIO_ADDR *wolfSSL_BIO_ADDR_new(void);
2163-
WOLFSSL_API void wolfSSL_BIO_ADDR_free(WOLFSSL_BIO_ADDR *addr);
2164-
WOLFSSL_API void wolfSSL_BIO_ADDR_clear(WOLFSSL_BIO_ADDR *addr);
2165-
#endif /* WOLFSSL_HAVE_BIO_ADDR */
2166-
21672169
#endif /* !NO_BIO */
21682170

21692171
WOLFSSL_API void wolfSSL_RAND_screen(void);

wolfssl/wolfcrypt/settings.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,10 @@ extern void uITRON4_free(void *p) ;
25942594
#endif /*(WOLFSSL_APACHE_MYNEWT)*/
25952595

25962596
#ifdef WOLFSSL_ZEPHYR
2597+
#ifdef __cplusplus
2598+
} /* extern "C" */
2599+
#endif
2600+
25972601
#include <version.h>
25982602
#if KERNEL_VERSION_NUMBER >= 0x30100
25992603
#include <zephyr/kernel.h>
@@ -2606,6 +2610,10 @@ extern void uITRON4_free(void *p) ;
26062610
#endif
26072611
#include <stdlib.h>
26082612

2613+
#ifdef __cplusplus
2614+
extern "C" {
2615+
#endif
2616+
26092617
#define WOLFSSL_DH_CONST
26102618
#define NO_WRITEV
26112619
#define NO_STDLIB_ISASCII

wolfssl/wolfcrypt/wc_port.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@
283283
#elif defined(WOLFSSL_APACHE_MYNEWT)
284284
/* do nothing */
285285
#elif defined(WOLFSSL_ZEPHYR)
286-
/* Zephyr SDK can use a cpp compiler which will cause
287-
* problems with extern "C" linkage if not handled */
288286
#ifdef __cplusplus
289287
} /* extern "C" */
290288
#endif
@@ -994,8 +992,16 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
994992
#define XFGETS(b,s,f) -2 /* Not ported yet */
995993

996994
#elif defined(WOLFSSL_ZEPHYR)
995+
#ifdef __cplusplus
996+
} /* extern "C" */
997+
#endif
998+
997999
#include <zephyr/fs/fs.h>
9981000

1001+
#ifdef __cplusplus
1002+
extern "C" {
1003+
#endif
1004+
9991005
#define XFILE struct fs_file_t*
10001006

10011007
/* These are our wrappers for opening and closing files to
@@ -1481,6 +1487,10 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
14811487
#define USE_WOLF_TIME_T
14821488

14831489
#elif defined(WOLFSSL_ZEPHYR)
1490+
#ifdef __cplusplus
1491+
} /* extern "C" */
1492+
#endif
1493+
14841494
#include <version.h>
14851495
#ifndef _POSIX_C_SOURCE
14861496
#if KERNEL_VERSION_NUMBER >= 0x30100
@@ -1500,6 +1510,10 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
15001510
#endif
15011511
#endif
15021512

1513+
#ifdef __cplusplus
1514+
extern "C" {
1515+
#endif
1516+
15031517
time_t z_time(time_t *timer);
15041518

15051519
#define XTIME(tl) z_time((tl))

wolfssl/wolfio.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@
176176
#include <lwip-socket.h>
177177
#include <errno.h>
178178
#elif defined(WOLFSSL_ZEPHYR)
179+
#ifdef __cplusplus
180+
} /* extern "C" */
181+
#endif
182+
179183
#include <version.h>
180184
#if KERNEL_VERSION_NUMBER >= 0x30100
181185
#include <zephyr/net/socket.h>
@@ -188,6 +192,10 @@
188192
#include <posix/sys/socket.h>
189193
#endif
190194
#endif
195+
196+
#ifdef __cplusplus
197+
extern "C" {
198+
#endif
191199
#elif defined(MICROCHIP_PIC32)
192200
#include <sys/errno.h>
193201
#elif defined(HAVE_NETX)
@@ -533,7 +541,11 @@
533541
typedef struct hostent HOSTENT;
534542
#endif /* HAVE_SOCKADDR */
535543

536-
#if defined(HAVE_GETADDRINFO)
544+
#if defined(WOLFSSL_ZEPHYR)
545+
typedef struct zsock_addrinfo ADDRINFO;
546+
#define getaddrinfo zsock_getaddrinfo
547+
#define freeaddrinfo zsock_freeaddrinfo
548+
#elif defined(HAVE_GETADDRINFO)
537549
typedef struct addrinfo ADDRINFO;
538550
#endif
539551
#endif /* WOLFSSL_NO_SOCK */
@@ -573,6 +585,10 @@ union WOLFSSL_BIO_ADDR {
573585

574586
typedef union WOLFSSL_BIO_ADDR WOLFSSL_BIO_ADDR;
575587

588+
WOLFSSL_API WOLFSSL_BIO_ADDR *wolfSSL_BIO_ADDR_new(void);
589+
WOLFSSL_API void wolfSSL_BIO_ADDR_free(WOLFSSL_BIO_ADDR *addr);
590+
WOLFSSL_API void wolfSSL_BIO_ADDR_clear(WOLFSSL_BIO_ADDR *addr);
591+
576592
#if defined(WOLFSSL_DTLS) && defined(OPENSSL_EXTRA)
577593
WOLFSSL_API int wolfIO_SendTo(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int wrFlags);
578594
WOLFSSL_API int wolfIO_RecvFrom(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, int sz, int rdFlags);
@@ -994,6 +1010,8 @@ WOLFSSL_API void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
9941010
#endif
9951011
#elif defined(FREESCALE_MQX)
9961012
#define XINET_PTON(a,b,c,d) inet_pton((a),(b),(c),(d))
1013+
#elif defined(WOLFSSL_ZEPHYR)
1014+
#define XINET_PTON(a,b,c) zsock_inet_pton((a),(b),(c))
9971015
#else
9981016
#define XINET_PTON(a,b,c) inet_pton((a),(b),(c))
9991017
#endif

0 commit comments

Comments
 (0)