INET_NTOP(3POSIX)
π INET_NTOP(3POSIX) π
okay bestie, welcome to the POSIX Programmer's Manual entry for inet_ntop and inet_pton β yes the manual name is literally right there in the title, 3POSIX, it's giving "section 3, POSIX edition" and I'm obsessed π
β¨ PROLOG β¨
okay so first thing, real talk: this page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so pls consult the corresponding Linux manual page for the deets on Linux behavior, fr fr), or the interface might not even be implemented on Linux at all. π
πΈ NAME πΈ
inet_ntop, inet_pton β convert IPv4 and IPv6 addresses between binary and text form π¦
β¨ SYNOPSIS β¨
#include <arpa/inet.h>
const char *inet_ntop(int af, const void *restrict src,
char *restrict dst, socklen_t size);
int inet_pton(int af, const char *restrict src, void *restrict dst);
π DESCRIPTION π
the inet_ntop() of it all π
inet_ntop() shall convert a numeric address into a text string suitable for presentation. The af argument shall specify the family of the address β this can be AF_INET or AF_INET6.
The src argument points to a buffer holding an IPv4 address if the af argument is AF_INET, or an IPv6 address if the af argument is AF_INET6; and the address must be in network byte order, no exceptions bestie.
The dst argument points to a buffer where the function stores the resulting text string; it shall not be NULL.
The size argument specifies the size of this buffer, which shall be large enough to hold the text string β that's INET_ADDRSTRLEN characters for IPv4, and INET6_ADDRSTRLEN characters for IPv6. Don't skimp on the buffer, she needs room to breathe π
and now inet_pton() π§
inet_pton() shall convert an address in its standard text presentation form into its numeric binary form. The af argument shall specify the family of the address. The AF_INET and AF_INET6 address families shall be supported.
The src argument points to the string being passed in. The dst argument points to a buffer into which the function stores the numeric address; this shall be large enough to hold the numeric address β that's 32 bits for AF_INET, 128 bits for AF_INET6. π
if af is AF_INET π
If the af argument of inet_pton() is AF_INET, the src string shall be in the standard IPv4 dotted-decimal form:
ddd.ddd.ddd.ddd
where "ddd" is a one to three digit decimal number between 0 and 255 (see inet_addr()).
not me being strict:inet_pton()does not accept other formats β like the octal numbers, hexadecimal numbers, and fewer than four numbers thatinet_addr()accepts. She's picky and honestly? valid. π
if af is AF_INET6 π¦
If the af argument of inet_pton() is AF_INET6, the src string shall be in one of the following standard IPv6 text forms:
- The preferred form is
"x:x:x:x:x:x:x:x", where the'x's are the hexadecimal values of the eight 16-bit pieces of the address. Leading zeros in individual fields can be omitted, but there shall be one to four hexadecimal digits in every field. β¨ - A string of contiguous zero fields in the preferred form can be shown as
"::". The"::"can only appear once in an address. Unspecified addresses ("0:0:0:0:0:0:0:0") may be represented simply as"::". iconic compression behavior honestly π - A third form that is sometimes more convenient when dealing with a mixed environment of IPv4 and IPv6 nodes is
"x:x:x:x:x:x:d.d.d.d", where the'x's are the hexadecimal values of the six high-order 16-bit pieces of the address, and the'd's are the decimal values of the four low-order 8-bit pieces of the address (standard IPv4 representation). π«Ά
Note: A more extensive description of the standard representations of IPv6 addresses can be found in RFC 2373. go read it if you want the deep lore, iykyk π
π₯ RETURN VALUE π₯
inet_ntop() shall return a pointer to the buffer containing the text string if the conversion succeeds, and NULL otherwise β and set errno to indicate the error. π
inet_pton() shall return 1 if the conversion succeeds, with the address pointed to by dst in network byte order. It shall return 0 if the input is not a valid IPv4 dotted-decimal string or a valid IPv6 address string, or -1 with errno set to [EAFNOSUPPORT] if the af argument is unknown. three whole outcomes, main character energy fr fr π
π ERRORS π
The inet_ntop() and inet_pton() functions shall fail if:
EAFNOSUPPORTβ Theafargument is invalid. πENOSPCβ The size of theinet_ntop()result buffer is inadequate. (your buffer was too small bestie, it's giving cramped π )
The following sections are informative.
π EXAMPLES π
None.
π APPLICATION USAGE π
None.
π RATIONALE π
None.
β FUTURE DIRECTIONS β
None.
π SEE ALSO π
The Base Definitions volume of POSIX.1β2017, <arpa_inet.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie π«Ά brought to you by IEEE/The Open Group, 2017 β stay converting, stay iconic, mwah πβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms