]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add tor_htonll/ntohll functions
authorDavid Goulet <dgoulet@ev0ke.net>
Mon, 11 Jan 2016 10:13:04 +0000 (11:13 +0100)
committerDavid Goulet <dgoulet@torproject.org>
Mon, 20 Jun 2016 19:26:58 +0000 (15:26 -0400)
Signed-off-by: David Goulet <dgoulet@ev0ke.net>
src/common/util.c
src/common/util.h

index 4b6df81b7d06476125ce3153b3de4bc0728827fe..3c5341d4604c0b3f8ddfeb145ff10557b4793e05 100644 (file)
@@ -5587,3 +5587,24 @@ clamp_double_to_int64(double number)
   return signbit(number) ? INT64_MIN : INT64_MAX;
 }
 
+/** Return a uint64_t value from <b>a</b> in network byte order. */
+uint64_t
+tor_htonll(uint64_t a)
+{
+#ifdef WORDS_BIGENDIAN
+  /* Big endian. */
+  return a;
+#else /* WORDS_BIGENDIAN */
+  /* Little endian. The worst... */
+  return htonl((uint32_t)(a>>32)) |
+    (((uint64_t)htonl((uint32_t)a))<<32);
+#endif /* WORDS_BIGENDIAN */
+}
+
+/** Return a uint64_t value from <b>a</b> in host byte order. */
+uint64_t
+tor_ntohll(uint64_t a)
+{
+  return tor_htonll(a);
+}
+
index 7cb33dc680bc3c75f3ecfd8f478c9a2a667f8732..fdf1c03b6ee1ffeb17379128e22437cec3202272 100644 (file)
@@ -61,6 +61,8 @@ void *tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS)
 void *tor_memdup_nulterm_(const void *mem, size_t len DMALLOC_PARAMS)
   ATTR_MALLOC ATTR_NONNULL((1));
 void tor_free_(void *mem);
+uint64_t tor_htonll(uint64_t a);
+uint64_t tor_ntohll(uint64_t a);
 #ifdef USE_DMALLOC
 extern int dmalloc_free(const char *file, const int line, void *pnt,
                         const int func_id);