大小端转换htonl、ntohl、htons、ntohs

本文详细介绍了在TCP/IP网络中用于大小端转换的函数:htonl, ntohl, htons 和 ntohs。这些函数分别将32位和16位数值从主机字节顺序转换为网络字节顺序,反之亦然。特别地,htonl和ntohl适用于32位数值,htons和ntohs则用于16位数值。在Intel处理器上,主机字节顺序为小尾(little-endian),而网络字节顺序为大尾(big-endian)。这些函数在不同CPU字节顺序间确保数据的正确传输。" 122177765,10125493,MIPS开发板上的NFS系统移植教程,"['嵌入式开发', 'Linux系统', '网络服务', 'MIPS架构', '文件系统']
摘要由CSDN通过智能技术生成

htonl

The htonl function converts a u_long from host to TCP/IP network byte order (which is big-endian).

u_long htonl(
  u_long hostlong  
);
Parameters
hostlong
[in] 32-bit number in host byte order.
Return Values

The htonl function returns the value in TCP/IP's network byte order.

Remarks

The htonl function takes a 32-bit number in host byte order and returns a 32-bit number in the network byte order used in TCP/IP networks.

Requirements

  Windows NT/2000/XP: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Winsock2.h.

  Library: Use Ws2_32.lib.


ntohl

The ntohl function converts a u_long from TCP/IP network order to host byte order (which is little-endian on Intel processors).

u_long ntohl(
  u_long netlong  
);
Parameters
netlong
[in] 32-bit number in TCP/IP network byte order.
Return Values

The ntohl function always returns a value in host byte order. If the netlong parameter was already in host byte order, then no operation is performed.

Remarks

The ntohl function takes a 32-bit number in TCP/IP network byte order and returns a 32-bit number in host byte order.

Requirements
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值