summaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2024-01-17 10:57:32 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2024-01-17 10:57:32 +0000
commit55d0abad892e472b6e6f130efaed48cf5c5145b5 (patch)
tree85f524212637797f0533d32f495d9a50996c28b1 /compat
parent7d91b4b90b1eac9fe04a2fab22013bfbb9ff5ee1 (diff)
Need htonll and ntohll.
Diffstat (limited to 'compat')
-rw-r--r--compat/htonll.c30
-rw-r--r--compat/imsg-buffer.c7
-rw-r--r--compat/ntohll.c30
3 files changed, 67 insertions, 0 deletions
diff --git a/compat/htonll.c b/compat/htonll.c
new file mode 100644
index 00000000..aef65983
--- /dev/null
+++ b/compat/htonll.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2024 Nicholas Marriott <nicholas.marriott@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include "compat.h"
+
+uint64_t
+htonll(uint64_t v)
+{
+ uint32_t b;
+ uint32_t t;
+
+ b = htonl (v & 0xffffffff);
+ t = htonl (v >> 32);
+ return ((uint64_t)b << 32 | t);
+}
diff --git a/compat/imsg-buffer.c b/compat/imsg-buffer.c
index ea236efd..9aed0ed3 100644
--- a/compat/imsg-buffer.c
+++ b/compat/imsg-buffer.c
@@ -20,6 +20,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
+#include <arpa/inet.h>
#include <limits.h>
#include <errno.h>
@@ -31,11 +32,17 @@
#include "compat.h"
#include "imsg.h"
+#undef htobe16
#define htobe16 htons
+#undef htobe32
#define htobe32 htonl
+#undef htobe64
#define htobe64 htonll
+#undef be16toh
#define be16toh ntohs
+#undef be32toh
#define be32toh ntohl
+#undef be64toh
#define be64toh ntohll
static int ibuf_realloc(struct ibuf *, size_t);
diff --git a/compat/ntohll.c b/compat/ntohll.c
new file mode 100644
index 00000000..c2fe1bb7
--- /dev/null
+++ b/compat/ntohll.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2024 Nicholas Marriott <nicholas.marriott@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include "compat.h"
+
+uint64_t
+ntohll(uint64_t v)
+{
+ uint32_t b;
+ uint32_t t;
+
+ b = ntohl (v & 0xffffffff);
+ t = ntohl (v >> 32);
+ return ((uint64_t)b << 32 | t);
+}