inet_ntop(3)

✨ inet_ntop β€” the "address, but make it text" glow-up ✨

okay bestie, pull up a chair 🫢 literally the manual page for inet_ntop(3), and it lives in section 3 of the library functions manual. it's the girl who takes your computer-brain binary address and turns it into something a human can actually read. no cap.


πŸ’– NAME πŸ’–

inet_ntop β€” convert IPv4 and IPv6 addresses from binary to text form

so basically "network to presentation" and yes the n and p in the name are exactly that, she's giving exactly what she says on the tin πŸ’…


πŸ“š LIBRARY πŸ“š

Standard C library β€” that's libc, link it with -lc.


πŸŽ€ SYNOPSIS πŸŽ€

#include <arpa/inet.h>

const char *inet_ntop(socklen_t size;
                      int af, const void *restrict src,
                      char dst[restrict size], socklen_t size);

yes the prototype really does open with socklen_t size; like that, that's not a typo on my part, that's just what the page says, and we do not editorialize about it 😭


🌸 DESCRIPTION 🌸

okay so the whole vibe of this function: you hand her a network address structure called src, you tell her which address family it belongs to with af, and she writes back a cute little character string version of it. that string gets copied into the buffer that dst points at.

dst must be a non-null pointer. non-negotiable, she will not work with a null, do not test her πŸ™ˆ

and like, how much room does she have? you tell her! you pass the number of bytes available in that buffer through the argument size. you're the one in charge of the real estate, she just decorates it.

inet_ntop() is literally the glow-up of inet_ntoa(3) β€” she extends it so it can handle multiple address families at once. and honestly? inet_ntoa(3) is now considered deprecated in favor of inet_ntop(). so like, respectfully, move on bestie. the old one had its era, this is the new era. periodt.

here are the address families she currently supports, bestie:

  • AF_INET β€” src points to a struct in_addr (in network byte order πŸ¦‹) and she converts it into an IPv4 network address in the good old dotted-decimal format, "ddd.ddd.ddd.ddd". your buffer dst has to be at least INET_ADDRSTRLEN bytes long. that's the minimum, don't come at her with less.
  • AF_INET6 β€” src points to a struct in6_addr (also network byte order) and she converts it into a representation of that address in the most appropriate IPv6 network address format for this particular address. she picks the best-looking one, she's thoughtful like that. your buffer dst has to be at least INET6_ADDRSTRLEN bytes long.

🌈 RETURN VALUE 🌈

  • on success πŸŽ‰ she returns a non-null pointer to dst.
  • on error πŸ’€ she returns NULL, and errno gets set to tell you what went wrong.

πŸ’œ ERRORS πŸ’œ

  • EAFNOSUPPORT β€” af was not a valid address family. like girl, that family doesn't exist, she cannot work with that.
  • ENOSPC β€” the converted address string would exceed the size you gave her. you didn't give her enough room and she's telling you so. iconic of her, honestly.

πŸ‘‘ ATTRIBUTES πŸ‘‘

for the explanation of the terms used in this section, see attributes(7) 🌟

  • Interface: inet_ntop()
  • Attribute: Thread safety
  • Value: MT-Safe locale

that's the whole table, one row, she's low maintenance πŸŽ€


⭐ STANDARDS ⭐

POSIX.1-2008.


πŸ¦‹ HISTORY πŸ¦‹

POSIX.1-2001.

also a lil history lesson, since we love lore here: RFC 2553 defines a prototype where the last argument size is of type size_t. many systems follow RFC 2553. glibc 2.0 and 2.1 had size_t, but 2.2 and later have socklen_t. glow-up era for the type, basically ✨


πŸ’€ BUGS πŸ’€

AF_INET6 converts IPv4-mapped IPv6 addresses into an IPv6 format. that's it, that's the note. it's giving known quirk, iykyk.


πŸ“ EXAMPLES πŸ“

see inet_pton(3). she's not doing examples today, go bother her sister.


🧚 SEE ALSO 🧚


ok real talk bestie: watch your buffer sizes. INET_ADDRSTRLEN and INET6_ADDRSTRLEN are the floors, not suggestions. and always, always check for that NULL return. no cap πŸ’…

and that's the whole page!! 🫢 this was pulled from Linux man-pages 6.20, dated 2025-06-28, for inet_ntop(3) β€” so if you're reading this in a year and something changed, blame the future, not me. slay, go convert some addresses, you've got this πŸ’–βœ¨πŸŒΈ

πŸ“¦ 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms