BYTEORDER(3)
๐ BYTEORDER โ ok so bestie, let's talk htonl, htons, ntohl, ntohs ๐
This is the BYTEORDER(3) page (yes that's the manual name, she's literally the title, iconic) โ and it's about the four little functions that make your bytes stop fighting each other and just get along. Converting values between host and network byte order. No cap. ๐ฆ
๐ LIBRARY
Standard C library โ libc, -lc. She lives in libc, she's been there forever, she's practically a legacy queen ๐
โจ SYNOPSIS
#include <arpa/inet.h>
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
Four functions, four signatures, all of them completely chill. Copy them exactly, bestie, don't freestyle ๐
๐ธ DESCRIPTION
Okay so here's the whole vibe. Your computer (the host) and the internet (the network) do NOT agree on which end of a number comes first. It's giving two friends who can't agree on where to sit at lunch. These four functions are the group chat mediator ๐
htonl()โ takes that unsigned integerhostlongand converts it from host byte order to network byte order. h-t-o-n-l, "host to network, long." Long = 32-bit. Easy ๐htons()โ same deal but for the unsigned short integerhostshort, going from host byte order to network byte order. s = short. Little guy. 16-bit. Tiny but fierce โจntohl()โ reverse direction, babe. Converts the unsigned integernetlongfrom network byte order to host byte order. n-t-o-h-l. Network to host. Long again. ๐ntohs()โ and the last one, converts the unsigned short integernetshortfrom network byte order to host byte order. Short one. Rounding out the squad. ๐ซถ
Now the tea โ โ on the i386, the host byte order is Least Significant Byte first, whereas the network byte order, as used on the Internet, is Most Significant Byte first. So yeah, they're opposites. That's the whole reason these functions exist, and honestly? She ate. ๐ฅ
๐งต ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). Go read it, I'm not doing your homework for you ๐
htonl(),htons(),ntohl(),ntohs()โ Thread safety:MT-Safe๐
Translation: all four of them are MT-Safe, so you can call them from multiple threads and they will not start drama. Main character energy, every single one. No locks, no chaos, just vibes ๐
๐ STANDARDS
POSIX.1-2008. Certified. Standardized. On the list. Periodt ๐
๐ฐ๏ธ HISTORY
POSIX.1-2001. She's been around a minute, lowkey a legend at this point ๐
๐ SEE ALSO
Go read those too. Expanding your knowledge is self care ๐ง๐
Okay that's the whole page, bestie!! You now understand byte order better than 90% of people who write network code, which is honestly a low bar but still, slay ๐
Mwah ๐ โ this was Linux man-pages 6.20, dated 2026-02-08. Bye bestie, go convert some bytes ๐ฆโจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms