Section: POSIX Programmer's Manual (3P)
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
--- convert IPv4 and IPv6 addresses between binary and text form
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);
function shall convert a numeric address into a text string suitable
for presentation. The
argument shall specify the family of the address. This can be AF_INET
argument points to a buffer holding an IPv4 address if the
argument is AF_INET,
or an IPv6 address if the
argument is AF_INET6;
the address must be in network byte order. The
argument points to a buffer where the function stores the resulting
text string; it shall not be NULL. The
argument specifies the size of this buffer, which shall be large enough
to hold the text string (INET_ADDRSTRLEN characters for IPv4,
INET6_ADDRSTRLEN characters for IPv6).
function shall convert an address in its standard text presentation
form into its numeric binary form. The
argument shall specify the family of the address. The AF_INET
address families shall be supported. The
argument points to the string being passed in. The
argument points to a buffer into which the function stores the numeric
address; this shall be large enough to hold the numeric address (32 bits
128 bits for AF_INET6).
is AF_INET, the
string shall be in the standard IPv4 dotted-decimal form:
is a one to three digit decimal number between 0 and 255 (see
function does not accept other formats (such as the octal numbers,
hexadecimal numbers, and fewer than four numbers that
is AF_INET6, the
string shall be in one of the following standard IPv6 text forms:
The preferred form is
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 at
least one numeral in every field.
A string of contiguous zero fields in the preferred form can be shown
can only appear once in an address. Unspecified addresses ("0:0:0:0:0:0:0:0")
may be represented simply as
A third form that is sometimes more convenient when dealing with a
mixed environment of IPv4 and IPv6 nodes is
are the hexadecimal values of the six high-order 16-bit pieces of the
address, and the
are the decimal values of the four low-order 8-bit pieces of the
address (standard IPv4 representation).
A more extensive description of the standard representations of IPv6
addresses can be found in RFC 2373.
function shall return a pointer to the buffer containing the text
string if the conversion succeeds, and NULL otherwise, and set
to indicate the error.
function shall return 1 if the conversion succeeds, with the address
pointed to by
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
argument is unknown.
functions shall fail if:
argument is invalid.
The size of the
result buffer is inadequate.
The following sections are informative.
The Base Definitions volume of POSIX.1-2008,
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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
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