Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1722898
  • 博文数量: 143
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1462
  • 用 户 组: 普通用户
  • 注册时间: 2016-08-23 11:14
文章分类

全部博文(143)

文章存档

2022年(3)

2021年(13)

2020年(21)

2019年(8)

2018年(28)

2017年(7)

2016年(63)

我的朋友

分类: LINUX

2020-04-03 15:59:57

1. 在linux kernel的netinet/in.h中
# if __BYTE_ORDER == __BIG_ENDIAN
/* The host byte order is the same as network byte order,
   so these functions are all just identity.  */
# define ntohl(x)    (x)
# define ntohs(x)    (x)
# define htonl(x)    (x)
# define htons(x)    (x)
# else
#  if __BYTE_ORDER == __LITTLE_ENDIAN
#   define ntohl(x)    __bswap_32 (x)
#   define ntohs(x)    __bswap_16 (x)
#   define htonl(x)    __bswap_32 (x)
#   define htons(x)    __bswap_16 (x)
#  endif
# endif
# endif

2. 在gcc中
#define __bswap_32(x) ((unsigned int)__builtin_bswap32(x))

3. 在gcc中
/* Swap bytes in 32 bit value.  */
#define __builtin_bswap32(x) \
     ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >>  8) |         \
      (((x) & 0x0000ff00u) <<  8) | (((x) & 0x000000ffu) << 24))
阅读(4938) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~