aboutsummaryrefslogtreecommitdiff
path: root/src/lib/arch
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-06-28 13:26:27 -0400
committerNick Mathewson <nickm@torproject.org>2018-06-28 13:26:27 -0400
commit8fc15e4861b37f7799abde6b9d6ec63fdceb55da (patch)
tree47b2aea50a083f404e06a605e0cec3296dbfcb23 /src/lib/arch
parent4dda026f0da05dfccf4fb8a13492b81af9324a39 (diff)
downloadtor-8fc15e4861b37f7799abde6b9d6ec63fdceb55da.tar.gz
tor-8fc15e4861b37f7799abde6b9d6ec63fdceb55da.zip
Add ntohs and htons to lib/arch/bytes.h
Diffstat (limited to 'src/lib/arch')
-rw-r--r--src/lib/arch/bytes.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/arch/bytes.h b/src/lib/arch/bytes.h
index dcd35ae4fe..d3b53f8cdf 100644
--- a/src/lib/arch/bytes.h
+++ b/src/lib/arch/bytes.h
@@ -87,6 +87,18 @@ set_uint64(void *cp, uint64_t v)
}
#ifdef WORDS_BIGENDIAN
+static inline uint16_t
+tor_htons(uint32_t a)
+{
+ return a;
+}
+
+static inline uint16_t
+tor_ntohs(uint64_t a)
+{
+ return a;
+}
+
static inline uint32_t
tor_htonl(uint32_t a)
{
@@ -111,6 +123,21 @@ tor_ntohll(uint64_t a)
return a;
}
#else
+static inline uint16_t
+tor_htons(uint16_t a)
+{
+ /* Our compilers will indeed recognize this as bswap. */
+ return
+ ((a & 0x00ff) << 8) |
+ ((a & 0xff00) >> 8);
+}
+
+static inline uint16_t
+tor_ntohs(uint16_t a)
+{
+ return tor_htons(a);
+}
+
static inline uint32_t
tor_htonl(uint32_t a)
{