V2EX ntohs

Ntohs

释义 Definition

ntohs 是 C/C++ 网络编程中常见的函数/宏名,表示 “network to host short”:把16 位(short)的端口号等数值从网络字节序(大端序)转换为主机字节序,以便在不同 CPU 架构(大小端不同)上正确解释数据。常用于读取 TCP/UDP 头部中的端口号字段。
(同类还有 ntohl 用于 32 位。)

发音 Pronunciation (IPA)

/n ti o et s/

例句 Examples

The code uses ntohs to read the port number correctly.
这段代码使用 ntohs 来正确读取端口号。

After receiving a packet, the program converts the 16-bit fields with ntohs before logging them, ensuring the values are correct on both little-endian and big-endian systems.
接收数据包后,程序在记录日志前用 ntohs 转换这些 16 位字段,确保在小端和大端系统上数值都正确。

词源 Etymology

ntohs 来自缩写 n(network) + to + h(host) + s(short)。它属于 BSD sockets 传统接口的一分:网络协议规定多字节整数通常使用网络字节序(大端),而主机可能是小端或大端,因此需要显式转换。

相关词 Related Words

文学与经典作品 Literary Works

  • UNIX Network Programming(W. Richard Stevens):在讲解字节序与 sockets API 时会频繁出现 ntohs/htons
  • TCP/IP Illustrated, Volume 1(W. Richard Stevens):讨论协议字段与网络字节序时常引用相关转换。
  • Beej’s Guide to Network Programming(Beej Jorgensen):入门网络编程教程中用 ntohs 解析端口号是典型示例。
关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2981 人在线   最高记录 6679       Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 42ms UTC 07:29 PVG 15:29 LAX 00:29 JFK 03:29
Do have faith in what you're doing.
ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86