From 5b449506cb237b2cadc61873e5113ee16b6393b3 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 9 Oct 2023 19:13:11 -0400 Subject: [PATCH] Add fart.hton module --- src/fart/hton.d | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/fart/hton.d diff --git a/src/fart/hton.d b/src/fart/hton.d new file mode 100644 index 0000000..b1aed31 --- /dev/null +++ b/src/fart/hton.d @@ -0,0 +1,35 @@ +/** + * @file + * + * Host to network byte-swapping functions. + */ + +module fart.hton; + +version (BigEndian) +{ + public uint htonl(uint v) + { + return v; + } + + public uint ntohl(uint v) + { + return v; + } +} + +version (LittleEndian) +{ + import core.bitop; + + public uint htonl(uint v) + { + return bswap(v); + } + + public uint ntohl(uint v) + { + return bswap(v); + } +}