V2EX  ›  英汉词典

Ntohl

释义 Definition

ntohl 是 C/C++ 套接字编程中的函数名,表示 network to host long:把一个 32 位无符号整数从网络字节序(通常是大端,big-endian)转换为主机字节序(取决于机器架构)。常用于解析网络协议头部字段(如 IPv4 地址、长度等)。
(它还有同系列的 ntohs/htonl/htons 用于不同位宽与方向。)

发音 Pronunciation (IPA)

/ˌɛn.tiː.oʊˈeɪtʃ.ɛl/

例句 Examples

Use ntohl to convert the 32-bit value from network byte order to host byte order.
使用 ntohl 将 32 位数值从网络字节序转换为主机字节序。

After reading the length field from the packet header, the program calls ntohl before allocating a buffer to avoid interpreting the bytes incorrectly on little-endian systems.
从数据包头读取长度字段后,程序会先调用 ntohl,再分配缓冲区,以避免在小端系统上误读字节顺序。

词源 Etymology

ntohl 是由缩写组合而成:n(network) + to + h(host) + l(long)。它源自早期 BSD 套接字接口的命名传统,用简短的函数名表达“字节序转换”的方向与位宽。

相关词 Related Words

文学与著作中的用例 Literary Works

  • UNIX Network Programming, Volume 1: The Sockets Networking API(W. Richard Stevens 等):在讲解字节序与套接字 API 时常出现 ntohl
  • Beej’s Guide to Network Programming(Beej):在入门示例与数据解析章节中介绍并使用 ntohl
  • The Linux Programming Interface(Michael Kerrisk):在网络编程与协议处理相关内容中提到该类字节序转换函数(包括 ntohl)。
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1700 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 9ms · UTC 16:11 · PVG 00:11 · LAX 08:11 · JFK 11:11
♥ Do have faith in what you're doing.