diff --git a/mqtt_websockets/Makefile b/mqtt_websockets/Makefile
index 8eb5e56..c8216bc 100644
--- mqtt_websockets/Makefile
+++ mqtt_websockets/Makefile
@@ -12,7 +12,7 @@
 # If not, see <https://www.gnu.org/licenses/>.
 
 CC = gcc -std=gnu99
-CFLAGS = -Wextra -Wall `pkg-config --cflags openssl`
+CFLAGS = -Wextra -Wall `pkg-config --cflags openssl` `pkg-config --cflags libcrypto`
 BUILD_DIR = build
 
 # dir having our version of mqtt_pal.h must preceede dir of MQTT-C to override this hdr
diff --git a/mqtt_websockets/src/include/common_internal.h b/mqtt_websockets/src/include/common_internal.h
index 066e85a..54024d5 100644
--- mqtt_websockets/src/include/common_internal.h
+++ mqtt_websockets/src/include/common_internal.h
@@ -18,4 +18,6 @@
 #define OPENSSL_VERSION_110 0x10100000L
 #define OPENSSL_VERSION_111 0x10101000L
 
+#include "endian_compat.h"
+
 #endif /* COMMON_INTERNAL_H */
diff --git a/mqtt_websockets/src/include/endian_compat.h b/mqtt_websockets/src/include/endian_compat.h
new file mode 100644
index 0000000..076ccbe
--- /dev/null
+++ mqtt_websockets/src/include/endian_compat.h
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-3.0-only
+//
+// This program is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along with this program.
+// If not, see <https://www.gnu.org/licenses/>.
+
+#ifndef MQTT_WSS_ENDIAN_COMPAT_H
+#define MQTT_WSS_ENDIAN_COMPAT_H
+
+#ifdef __APPLE__
+    #include <libkern/OSByteOrder.h>
+
+    #define htobe16(x) OSSwapHostToBigInt16(x)
+    #define htole16(x) OSSwapHostToLittleInt16(x)
+    #define be16toh(x) OSSwapBigToHostInt16(x)
+    #define le16toh(x) OSSwapLittleToHostInt16(x)
+
+    #define htobe32(x) OSSwapHostToBigInt32(x)
+    #define htole32(x) OSSwapHostToLittleInt32(x)
+    #define be32toh(x) OSSwapBigToHostInt32(x)
+    #define le32toh(x) OSSwapLittleToHostInt32(x)
+
+    #define htobe64(x) OSSwapHostToBigInt64(x)
+    #define htole64(x) OSSwapHostToLittleInt64(x)
+    #define be64toh(x) OSSwapBigToHostInt64(x)
+    #define le64toh(x) OSSwapLittleToHostInt64(x)
+#else
+#ifdef __FreeBSD__
+    #include <sys/endian.h>
+#else
+    #include <endian.h>
+#endif
+#endif
+
+#endif /* MQTT_WSS_ENDIAN_COMPAT_H */
diff --git a/mqtt_websockets/src/mqtt_wss_client.c b/mqtt_websockets/src/mqtt_wss_client.c
index 8b7261b..25f99c0 100644
--- mqtt_websockets/src/mqtt_wss_client.c
+++ mqtt_websockets/src/mqtt_wss_client.c
@@ -196,7 +196,11 @@ mqtt_wss_client mqtt_wss_new(const char *log_prefix,
 
     client->log = log;
 
+#ifdef __APPLE__
+    if (pipe(client->write_notif_pipe)) {
+#else
     if (pipe2(client->write_notif_pipe, O_CLOEXEC /*| O_DIRECT*/)) {
+#endif
         mws_error(log, "Couldn't create pipe");
         goto fail_2;
     }
@@ -640,7 +644,11 @@ int mqtt_wss_connect(mqtt_wss_client client, char *host, int port, struct mqtt_c
 
 static inline uint64_t boottime_usec(mqtt_wss_client client) {
     struct timespec ts;
-    if(clock_gettime(CLOCK_BOOTTIME, &ts) == -1) {
+#if defined(__APPLE__) || defined(__FreeBSD__)
+    if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) {
+#else
+    if (clock_gettime(CLOCK_BOOTTIME, &ts) == -1) {
+#endif
         mws_error(client->log, "clock_gettimte failed");
         return 0;
     }
diff --git a/mqtt_websockets/src/ws_client.c b/mqtt_websockets/src/ws_client.c
index 3e71d9a..43c2ced 100644
--- mqtt_websockets/src/ws_client.c
+++ mqtt_websockets/src/ws_client.c
@@ -14,7 +14,6 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
-#include <endian.h>
 #include <errno.h>
 #include <ctype.h>
 
