]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
add nctoh64() utility
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 29 Oct 2021 13:45:51 +0000 (14:45 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Fri, 29 Oct 2021 13:45:51 +0000 (14:45 +0100)
general-utilities.c
general-utilities.h

index 87dc13d6c7a9e5353e0e1271f001e18490764c46..304de0b287c0320dd406406df6900be131d3a56c 100644 (file)
@@ -34,6 +34,16 @@ void hcton64(uint64_t num, uint8_t *p) {
   memcpy(p, &rev, sizeof(uint32_t));
 }
 
+uint64_t nctoh64(const uint8_t *p) { // read 4 characters from *p and do ntohl on them
+  // this is to avoid possible aliasing violations
+  uint64_t value = nctohl(p);
+  uint64_t value_low = nctohl(p+4);
+  value = value << 32;
+  value = value + value_low;
+  return value;
+}
+
+
 uint32_t nctohl(const uint8_t *p) { // read 4 characters from *p and do ntohl on them
   // this is to avoid possible aliasing violations
   uint32_t holder;
index b371614fb8bddd90a4091ce58ef098e0cbdc5b59..79f34f338ff945cbe167bea66ea1641ce5f67bbd 100644 (file)
 #endif
 
 void hcton64(uint64_t num, uint8_t *p);
-uint32_t nctohl(const uint8_t *p); // read 4 characters from *p and do ntohl on them, avoiding aliasing
+
+//these are designed to avoid aliasing check errors
+uint64_t nctoh64(const uint8_t *p);
+uint32_t nctohl(const uint8_t *p); 
 uint16_t nctohs(const uint8_t *p);
 uint64_t timespec_to_ns(struct timespec *tn);
 uint64_t get_time_now();