From 55d0abad892e472b6e6f130efaed48cf5c5145b5 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 17 Jan 2024 10:57:32 +0000 Subject: [PATCH] Need htonll and ntohll. --- compat.h | 10 ++++++++++ compat/htonll.c | 30 ++++++++++++++++++++++++++++++ compat/imsg-buffer.c | 7 +++++++ compat/ntohll.c | 30 ++++++++++++++++++++++++++++++ configure.ac | 4 +++- 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 compat/htonll.c create mode 100644 compat/ntohll.c diff --git a/compat.h b/compat.h index cabdf3ad..0693cf06 100644 --- a/compat.h +++ b/compat.h @@ -334,6 +334,16 @@ char *strndup(const char *, size_t); void *memmem(const void *, size_t, const void *, size_t); #endif +#ifndef HAVE_HTONLL +/* htonll.c */ +uint64_t htonll(uint64_t); +#endif + +#ifndef HAVE_NTOHLL +/* ntohll.c */ +uint64_t ntohll(uint64_t); +#endif + #ifndef HAVE_GETPEEREID /* getpeereid.c */ int getpeereid(int, uid_t *, gid_t *); 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 + * + * 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 + +#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 #include #include +#include #include #include @@ -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 + * + * 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 + +#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); +} diff --git a/configure.ac b/configure.ac index 020f21e5..6699ae63 100644 --- a/configure.ac +++ b/configure.ac @@ -148,7 +148,7 @@ AC_CHECK_FUNCS([ \ prctl \ proc_pidinfo \ getpeerucred \ - sysconf \ + sysconf ]) # Check for functions with a compatibility implementation. @@ -165,7 +165,9 @@ AC_REPLACE_FUNCS([ \ getpeereid \ getline \ getprogname \ + htonll \ memmem \ + ntohll \ setenv \ setproctitle \ strcasestr \