ntohs和htons区别?
来源:互联网 发布:战神诀披风进阶数据 编辑:程序博客网 时间:2024/05/02 04:49
一直以来都对这个两个函数含含糊糊的,今天又用到所以特意查看linux的源代码(/include/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
从上面的头文件内容可以看出,ntohs和htons是一样的。如果平台是大字序的(如Pocket PC),则这些函数不作任何转换,只有在平台是小字序时(如X86),这些函数才进行相应的转换,htons和ntohs(以及htonl和ntohl)实际上没有任何区别,都是把字节序反转,只在于使用者对网络端和主机端理解意义的不同。
- ntohs和htons区别?
- ntohs和htons的区别
- htons(), htonl(), ntohs(), ntohl()的区别和含义
- htons htonl ntohl ntohs 的区别和作用
- htonl htons ntohs ntohl的区别
- ntohs, ntohl, htons,htonl, inet_addr,inet_ntoa区别
- htonl htons ntohs ntohl的区别
- htons(), ntohl(), ntohs(),htons()
- htons(), ntohl(), ntohs(),htons()
- htons(), ntohl(), ntohs(),htons()
- htonl,htons 和 ntohs相关问题
- ntohs htons ntohl htonl比较和详解
- ntohs htons ntohl htonl比较和详解
- ntohs htons ntohl htonl比较和详解
- htonl,htons 和 ntohs相关问题
- htonl,htons 和 ntohs相关问题
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- xml基础-->总结
- 如何用xcode调试dylib
- (droid分享)新浪微博开发系列【四】之登录界面
- Wizard向导控件
- H.264解码器中参考图像的管理
- ntohs和htons区别?
- C++类型转换总结
- POJ 1161 Walls(floyd最短路)#by zh
- C++ 中#pragma 用法
- T6导入库存期初余额提示“类型不匹配”
- (droid分享)新浪微博开发系列【五】之显示主页
- httpd+xpm+libxml+jpegsrc+libpng+freetype+zlib+gd+php-5.2.2+ZendOptimizer-3.0.1+Mysql
- 分享45个android实例源码,很好很强大.收藏吧!!!
- request_mem_region 与 ioremap ,struct resource