INET_ADDR(3P)
π INET_ADDR(3P) β POSIX Programmer's Manual π
okay bestie, so this is inet_addr(3P) from the POSIX Programmer's Manual β and before we even get into it, there's a lil heads-up in the PROLOG you need to hear.
β¨ PROLOG β¨
So this manual page is part of the POSIX Programmer's Manual. But here's the tea: the Linux implementation of this interface may differ from what's written here β so if you're on Linux, pls consult the corresponding Linux manual page for the details of Linux behavior. And honestly? The interface might not even be implemented on Linux at all. π Not me warning you before you even start.
πΈ NAME πΈ
inet_addr, inet_ntoa β IPv4 address manipulation, periodt.
π SYNOPSIS π
#include <arpa/inet.h>
in_addr_t inet_addr(const char *cp);
char *inet_ntoa(struct in_addr in);
π¦ DESCRIPTION π¦
So, inet_addr() β what it does is it shall convert the string pointed to by cp, in the standard IPv4 dotted decimal notation, into an integer value suitable for use as an Internet address. Glow up from text to number, iconic.
And inet_ntoa() β she does the opposite vibe. She shall convert the Internet host address specified by in into a string in the Internet standard dot notation. Number to text. Slay.
π¨ Important caveat, bestie: inet_ntoa() need not be thread-safe. So like... don't be passing her around threads like she's chill, because she is not.
Also, ALL Internet addresses shall be returned in network order β that's bytes ordered from left to right. No cap.
Now here's the part where values specified using IPv4 dotted decimal notation take one of the following forms:
a.b.c.dβ When four parts are specified, each shall be interpreted as a byte of data and assigned, from left to right, to the four bytes of an Internet address. Four parts, four bytes, one-to-one, she's simple like that πa.b.cβ When a three-part address is specified, the last part shall be interpreted as a 16-bit quantity and placed in the rightmost two bytes of the network address. This makes the three-part address format convenient for specifying Class B network addresses as"128.net.host".a.bβ When a two-part address is supplied, the last part shall be interpreted as a 24-bit quantity and placed in the rightmost three bytes of the network address. This makes the two-part address format convenient for specifying Class A network addresses as"net.host".aβ When only one part is given, the value shall be stored directly in the network address without any byte rearrangement. Just raw, no filter, no rearrangement. π
And okay this next bit is the one people always get caught out by: all numbers supplied as parts in IPv4 dotted decimal notation may be decimal, octal, or hexadecimal, as specified in the ISO C standard. So:
- a leading
0xor0Ximplies hexadecimal - otherwise, a leading
'0'implies octal - otherwise, the number is interpreted as decimal
iykyk. that leading-zero thing is a whole personality trait and it WILL humble you. π«Ά
β RETURN VALUE β
Upon successful completion, inet_addr() shall return the Internet address. Otherwise, she shall return (in_addr_t)(-1). Yeah, bestie, -1. Not an error code, just that. That's the whole signal.
The inet_ntoa() function shall return a pointer to the network address in Internet standard dot notation.
π ERRORS π
No errors are defined. None. Zero. Nada. π
The following sections are informative.
π EXAMPLES π
None. I know, I know. Devastating.
π APPLICATION USAGE π
Okay this is the one that'll bite you: the return value of inet_ntoa() may point to static data that may be overwritten by subsequent calls to inet_ntoa(). So like β the pointer she hands you? She's borrowing it. From herself. And she wants it back next call. Copy that string if you need to keep it, fr fr. π
π§ RATIONALE π§
None.
π FUTURE DIRECTIONS π
None.
π SEE ALSO π
endhostent()endnetent()
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, version dated 2017, living under the name INET_ADDR(3P). mwah, go forth and parse those dotted decimals responsibly π«Άβ¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms