V2EX  ›  英汉词典

HTONL

Definition / 释义

htonl 是网络编程(BSD sockets)中常见的函数/宏名,表示 “Host TO Network Long”:把主机字节序(host byte order)的 32 位无符号整数转换为网络字节序(network byte order,通常为大端序)。常用于在发送 IP 地址、端口之外的 32 位字段前进行字节序转换。
(相关的还有 htons:16 位;以及 ntohl/ntohs:从网络字节序转回主机字节序。)

Pronunciation / 发音

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

Examples / 例句

I used htonl to convert the 32-bit value before sending it over the socket.
我在通过套接字发送之前用 htonl 把这个 32 位数值转换成网络字节序。

When constructing a custom protocol header, the code writes the length field as htonl(payload_length) to ensure consistent interpretation across different CPU architectures.
在构造自定义协议头时,代码把长度字段写成 htonl(payload_length),以确保在不同 CPU 架构上都能一致地解析。

Etymology / 词源

htonl 是缩写组合:h(host,主机) + to(到) + n(network,网络) + l(long,long 类型/32 位“长整型”概念)。它起源于早期 Unix/BSD 的网络接口设计,用于解决不同机器的字节序差异,使网络传输的数据在各平台间可互操作。

Related Words / 相关词

Literary Works / 文学与作品

  • UNIX Network Programming, Volume 1: The Sockets Networking API(W. Richard Stevens 等):在讲解字节序与套接字编程时频繁出现 htonl/htons/ntohl/ntohs
  • Beej’s Guide to Network Programming(Brian “Beej” Hall):入门教程中用 htonl 解释“网络字节序”的必要性与用法。
  • The Linux Programming Interface(Michael Kerrisk):在系统与网络编程相关章节中讨论字节序转换函数并出现 htonl
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1496 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 9ms · UTC 16:13 · PVG 00:13 · LAX 08:13 · JFK 11:13
♥ Do have faith in what you're doing.