• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <stdint.h>
20 
21 /*!
22  * \file
23  * \brief Endianness conversion interface.
24  * \addtogroup EpidCommon
25  * @{
26  */
27 
28 #if !defined(ntohl)
29 /// Macro to transform oct str 32 into uint_32
30 #define ntohl(u32)                                    \
31   ((uint32_t)(((((unsigned char*)&(u32))[0]) << 24) + \
32               ((((unsigned char*)&(u32))[1]) << 16) + \
33               ((((unsigned char*)&(u32))[2]) << 8) +  \
34               (((unsigned char*)&(u32))[3])))
35 #endif
36 
37 #if !defined(htonl)
38 /// Macro to transform uint_32 to network order
39 #define htonl(u32)                                   \
40   (uint32_t)(((((uint32_t)(u32)) & 0xFF) << 24) |    \
41              ((((uint32_t)(u32)) & 0xFF00) << 8) |   \
42              ((((uint32_t)(u32)) & 0xFF0000) >> 8) | \
43              ((((uint32_t)(u32)) & 0xFF000000) >> 24))
44 #endif
45 
46 /*! @} */
47 #endif  // EPID_COMMON_SRC_ENDIAN_CONVERT_H_
48