aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/utils/byteswap.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/host/include/uhd/utils/byteswap.hpp b/host/include/uhd/utils/byteswap.hpp
index dd5dcbc09..26d60c2ab 100644
--- a/host/include/uhd/utils/byteswap.hpp
+++ b/host/include/uhd/utils/byteswap.hpp
@@ -37,6 +37,12 @@ namespace uhd{
//! perform a byteswap on a 64 bit integer
boost::uint64_t byteswap(boost::uint64_t);
+ //! network to host: short, long, or long-long
+ template<typename T> T ntohx(T);
+
+ //! host to network: short, long, or long-long
+ template<typename T> T htonx(T);
+
} //namespace uhd
/***********************************************************************
@@ -117,4 +123,25 @@ namespace uhd{
#endif
+/***********************************************************************
+ * Define the templated network to/from host conversions
+ **********************************************************************/
+#include <boost/detail/endian.hpp>
+
+template<typename T> UHD_INLINE T uhd::ntohx(T num){
+ #ifdef BOOST_BIG_ENDIAN
+ return num;
+ #else
+ return uhd::byteswap(num);
+ #endif
+}
+
+template<typename T> UHD_INLINE T uhd::htonx(T num){
+ #ifdef BOOST_BIG_ENDIAN
+ return num;
+ #else
+ return uhd::byteswap(num);
+ #endif
+}
+
#endif /* INCLUDED_UHD_UTILS_BYTESWAP_HPP */