cmdmon: define 64-bit integer

Add a structure for 64-bit integers without requiring 64-bit alignment
to be usable in CMD_Reply without struct packing.

Add utility functions for conversion to/from network order. Avoid using
be64toh() and htobe64() as they don't seem to be available on all
supported systems.
This commit is contained in:
Miroslav Lichvar
2023-03-23 11:37:11 +01:00
parent 0845df7684
commit a511029cc2
4 changed files with 33 additions and 0 deletions

19
util.c
View File

@@ -909,6 +909,25 @@ UTI_TimespecHostToNetwork(const struct timespec *src, Timespec *dest)
/* ================================================== */
uint64_t
UTI_Integer64NetworkToHost(Integer64 i)
{
return (uint64_t)ntohl(i.high) << 32 | ntohl(i.low);
}
/* ================================================== */
Integer64
UTI_Integer64HostToNetwork(uint64_t i)
{
Integer64 r;
r.high = htonl(i >> 32);
r.low = htonl(i);
return r;
}
/* ================================================== */
#define FLOAT_EXP_BITS 7
#define FLOAT_EXP_MIN (-(1 << (FLOAT_EXP_BITS - 1)))
#define FLOAT_EXP_MAX (-FLOAT_EXP_MIN - 1)