diff options
Diffstat (limited to 'milkway/mw-byteorder.h')
-rw-r--r-- | milkway/mw-byteorder.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/milkway/mw-byteorder.h b/milkway/mw-byteorder.h index d934276..709f283 100644 --- a/milkway/mw-byteorder.h +++ b/milkway/mw-byteorder.h @@ -204,6 +204,69 @@ mw_letoh64 (mw_uint64_t u) #endif } +/** + * @brief convert a value to network byte order from host byte order + * + * @param u the integer in host order + * @return the value of integer in network byte order + */ +static mw_inline mw_uint16_t +mw_htons (mw_uint16_t u) +{ +#ifdef MW_WORDS_BIGENDIAN + return u; +#else + return mw_swap16 (u); +#endif +} + +/** + * @brief convert a value to host byte order from network byte order + * + * @param u the integer in host byte order(big endian) + * @return the value of integer in host byte order + */ +static mw_inline mw_uint16_t +mw_ntohs (mw_uint16_t u) +{ +#ifdef MW_WORDS_BIGENDIAN + return u; +#else + return mw_swap16 (u); +#endif +} + +/** + * @brief convert values to network byte order from host byte order + * + * @param u the integer in host byte order + * @return the value of integer in network byte order + */ +static mw_inline mw_uint32_t +mw_htonl (mw_uint32_t u) +{ +#ifdef MW_WORDS_BIGENDIAN + return u; +#else + return mw_swap32 (u); +#endif +} + +/** + * @brief convert values to host byte order from network byte order + * + * @param u the integer in network byte order + * @return the value of integer in host byte order + */ +static mw_inline mw_uint32_t +mw_ntohl (mw_uint32_t u) +{ +#ifdef MW_WORDS_BIGENDIAN + return u; +#else + return mw_swap32 (u); +#endif +} MW_END_DECLS #endif |