ntohl();ntohs();htons();htonl() 说明
来源:互联网 发布:飞翔快递单打印软件 编辑:程序博客网 时间:2024/05/17 08:58
在C/C++写网络程序的时候,往往会遇到字节的网络顺序和主机顺序的问题。这是就可能用到htons(), ntohl(), ntohs(),htons()这4个函数。
网络字节顺序与本地字节顺序之间的转换函数:
之所以需要这些函数是因为计算机数据表示存在两种字节顺序:NBO与HBO
网络字节顺序NBO(Network Byte Order):
按从高到低的顺序存储,在网络上使用统一的网络字节顺序,可以避免兼容性问题。
主机字节顺序(HBO,Host Byte Order):
不同的机器HBO不相同,与CPU设计有关,数据的顺序是由cpu决定的,而与操作系统无关。
如 Intel x86结构下,short型数0x1234表示为34 12, int型数0x12345678表示为78 56 34 12
如IBM power PC结构下,short型数0x1234表示为12 34, int型数0x12345678表示为12 34 56 78
由于这个原因不同体系结构的机器之间无法通信,所以要转换成一种约定的数序,也就是网络字节顺序,其实就是如同power pc那样的顺序 。在PC开发中有ntohl和htonl函数可以用来进行网络字节和主机字节的转换。
- ntohl();ntohs();htons();htonl() 说明
- htons()、htonl()、inet_ntoa()、ntohs()、ntohl()说明
- htons(), htonl(), ntohs(), ntohl()
- ntohs(),ntohl(),htons(),htonl(),
- htons(), htonl(), ntohs(), ntohl()
- htons(), htonl(), ntohs(), ntohl()
- htons,htonl,ntohs,ntohl
- htons(), htonl(), ntohs(), ntohl()
- htonl(), ntohl(), htons(), ntohs().
- htons,htonl,ntohs,ntohl
- htonl ntohl htons ntohs
- htons ntohs htonl ntohl
- htonl、htons、ntohl、ntohs
- ntohs, ntohl, htons,htonl
- ntohs,htons,ntohl,htonl
- htonl(), ntohl(), htons(), ntohs() 函数
- htonl(), ntohl(), htons(), ntohs() 函数
- htons(), htonl(), ntohs(), ntohl()详解
- RepeaterOrder双向排序
- C++为什么不加入垃圾回收机制
- Socket中如何设置连接超时
- vc显示数据大小(将十进制数据转化为Byte KB MB GB)
- moodle 2.0 群组 加入用户
- ntohl();ntohs();htons();htonl() 说明
- 位运算符
- sendRedirect()与forward()方法的异同
- android开机动画
- 2011-09-21 myeclipse出现的debug问题困扰
- CakePHP: Set::extract导致的内存消耗问题
- 遍历Request.ServerVariables 判断浏览器语言C# - [C#.NET]
- 什么是DQL、DML、DDL、DCL
- URL地址栏中的特殊字符