]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Add a net-to-host converter for 64-bit arithmetic
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 14 Jul 2022 09:10:19 +0000 (10:10 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 14 Jul 2022 09:10:19 +0000 (10:10 +0100)
general-utilities.c
general-utilities.h

index b758c773e93f0d0f0d18fb64e5ec43d8f1d079e7..a92a71d5f025a6b3e0b4d92f07f8244c4046cce4 100644 (file)
@@ -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;
index 3dbeb89fdc19e34d263cf002f3624cbc908ffea3..527b1ab4dba041a62668537ac69b485dde054eef 100644 (file)
@@ -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