endian_convert.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*############################################################################
  2. # Copyright 2016 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################*/
  16. #ifndef EPID_COMMON_SRC_ENDIAN_CONVERT_H_
  17. #define EPID_COMMON_SRC_ENDIAN_CONVERT_H_
  18. #include <stdint.h>
  19. /*!
  20. * \file
  21. * \brief Endianness conversion interface.
  22. * \addtogroup EpidCommon
  23. * @{
  24. */
  25. #if !defined(ntohl)
  26. /// Macro to transform oct str 32 into uint_32
  27. #define ntohl(u32) \
  28. ((uint32_t)(((((unsigned char*)&(u32))[0]) << 24) + \
  29. ((((unsigned char*)&(u32))[1]) << 16) + \
  30. ((((unsigned char*)&(u32))[2]) << 8) + \
  31. (((unsigned char*)&(u32))[3])))
  32. #endif
  33. #if !defined(htonl)
  34. /// Macro to transform uint_32 to network order
  35. #define htonl(u32) \
  36. (uint32_t)(((((uint32_t)(u32)) & 0xFF) << 24) | \
  37. ((((uint32_t)(u32)) & 0xFF00) << 8) | \
  38. ((((uint32_t)(u32)) & 0xFF0000) >> 8) | \
  39. ((((uint32_t)(u32)) & 0xFF000000) >> 24))
  40. #endif
  41. /*! @} */
  42. #endif // EPID_COMMON_SRC_ENDIAN_CONVERT_H_