为什么需要htons(), ntohl(), ntohs(),htons() 函数
来源:互联网 发布:mysql列名区分大小写吗 编辑:程序博客网 时间:2024/05/17 03:34
在C/C++写网络程序的时候,往往会遇到字节的网络顺序和主机顺序的问题。这是就可能用到htons(), ntohl(), ntohs(),htons()这4个函数。
网络字节顺序与本地字节顺序之间的转换函数:
htonl()--"Host to Network Long"
ntohl()--"Network to Host Long"
htons()--"Host to Network Short"
ntohs()--"Network to Host Short"
之所以需要这些函数是因为计算机数据表示存在两种字节顺序: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函数可以用来进行网络字节和主机字节的转换。
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数 .模拟htonl、ntohl、htons、ntohs函数实现
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数 .模拟htonl、ntohl、htons、ntohs函数实现
- 知道为什么需要htons(), ntohl(), ntohs(),htons() 函数吗?
- 网络编程时为什么需要htons()、ntohl()、ntohs()、htons() 函数?
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- htons(), ntohl(), ntohs(),htons() 函数
- RedHat9.0中安装qt4.5(x86) (转)
- 15款免费IDE,推荐给开发者
- c++和windows中获取时间问题
- TNS-12541: TNS: 无监听程序
- Java语言基础:final和static
- 为什么需要htons(), ntohl(), ntohs(),htons() 函数
- Intent小结
- 图标应用程序--添加、删除、保存图标
- 关于添加快捷方式的问题
- 交流测绘行业小程序
- CentOS下如何安装libevent
- 经典的委托排序
- Linux下使用C/C++访问数据库
- UltraEdit 使用技巧笔记