From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Thu, 14 Jul 2022 09:10:19 +0000 (+0100) Subject: Add a net-to-host converter for 64-bit arithmetic X-Git-Tag: 1.2~1^2~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d000a33ebd50fcde79162444a6a4c69efdf82e1;p=thirdparty%2Fnqptp.git Add a net-to-host converter for 64-bit arithmetic --- diff --git a/general-utilities.c b/general-utilities.c index b758c77..a92a71d 100644 --- a/general-utilities.c +++ b/general-utilities.c @@ -57,6 +57,19 @@ uint16_t nctohs(const uint8_t *p) { // read 2 characters from *p and do ntohs on return ntohs(holder); } +uint64_t ntoh64(const uint64_t n) { + uint64_t fiddle = n; + uint32_t fiddle_hi = fiddle & 0xFFFFFFFF; + fiddle_hi = ntohl(fiddle_hi); + fiddle = fiddle >> 32; + uint32_t fiddle_lo = fiddle & 0xFFFFFFFF; + fiddle_lo = ntohl(fiddle_lo); + fiddle = fiddle_hi; + fiddle = fiddle << 32; + fiddle = fiddle | fiddle_lo; + return fiddle; +} + uint64_t timespec_to_ns(struct timespec *tn) { uint64_t tnfpsec = tn->tv_sec; uint64_t tnfpnsec = tn->tv_nsec; diff --git a/general-utilities.h b/general-utilities.h index 3dbeb89..527b1ab 100644 --- a/general-utilities.h +++ b/general-utilities.h @@ -45,4 +45,6 @@ uint16_t nctohs(const uint8_t *p); uint64_t timespec_to_ns(struct timespec *tn); uint64_t get_time_now(); +uint64_t ntoh64(const uint64_t n); + #endif \ No newline at end of file