inet_ntop.3p (5418B)
- '\" et
- .TH INET_NTOP "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
- .\"
- .SH PROLOG
- 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.
- .\"
- .SH NAME
- inet_ntop,
- inet_pton
- \(em convert IPv4 and IPv6 addresses between binary and text form
- .SH SYNOPSIS
- .LP
- .nf
- #include <arpa/inet.h>
- .P
- const char *inet_ntop(int \fIaf\fP, const void *restrict \fIsrc\fP,
- char *restrict \fIdst\fP, socklen_t \fIsize\fP);
- int inet_pton(int \fIaf\fP, const char *restrict \fIsrc\fP, void *restrict \fIdst\fP);
- .fi
- .SH DESCRIPTION
- The
- \fIinet_ntop\fR()
- function shall convert a numeric address into a text string suitable
- for presentation. The
- .IR af
- argument shall specify the family of the address. This can be AF_INET
- or AF_INET6.
- The
- .IR src
- argument points to a buffer holding an IPv4 address if the
- .IR af
- argument is AF_INET,
- or an IPv6 address if the
- .IR af
- argument is AF_INET6;
- the address must be in network byte order. The
- .IR dst
- argument points to a buffer where the function stores the resulting
- text string; it shall not be NULL. The
- .IR size
- 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).
- .P
- The
- \fIinet_pton\fR()
- function shall convert an address in its standard text presentation
- form into its numeric binary form. The
- .IR af
- argument shall specify the family of the address. The AF_INET
- and AF_INET6
- address families shall be supported. The
- .IR src
- argument points to the string being passed in. The
- .IR dst
- 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
- for AF_INET,
- 128 bits for AF_INET6).
- .P
- If the
- .IR af
- argument of
- \fIinet_pton\fR()
- is AF_INET, the
- .IR src
- string shall be in the standard IPv4 dotted-decimal form:
- .sp
- .RS 4
- .nf
- ddd.ddd.ddd.ddd
- .fi
- .P
- .RE
- .P
- where
- .BR \(dqddd\(dq
- is a one to three digit decimal number between 0 and 255 (see
- .IR "\fIinet_addr\fR\^(\|)").
- The
- \fIinet_pton\fR()
- function does not accept other formats (such as the octal numbers,
- hexadecimal numbers, and fewer than four numbers that
- \fIinet_addr\fR()
- accepts).
- .P
- If the
- .IR af
- argument of
- \fIinet_pton\fR()
- is AF_INET6, the
- .IR src
- string shall be in one of the following standard IPv6 text forms:
- .IP " 1." 4
- The preferred form is
- .BR \(dqx:x:x:x:x:x:x:x\(dq ,
- where the
- .BR '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.
- .IP " 2." 4
- A string of contiguous zero fields in the preferred form can be shown
- as
- .BR \(dq::\(dq .
- The
- .BR \(dq::\(dq
- can only appear once in an address. Unspecified addresses (\c
- .BR \(dq0:0:0:0:0:0:0:0\(dq )
- may be represented simply as
- .BR \(dq::\(dq .
- .IP " 3." 4
- A third form that is sometimes more convenient when dealing with a
- mixed environment of IPv4 and IPv6 nodes is
- .BR \(dqx:x:x:x:x:x:d.d.d.d\(dq ,
- where the
- .BR 'x' s
- are the hexadecimal values of the six high-order 16-bit pieces of the
- address, and the
- .BR 'd' s
- are the decimal values of the four low-order 8-bit pieces of the
- address (standard IPv4 representation).
- .TP 10
- .BR Note:
- A more extensive description of the standard representations of IPv6
- addresses can be found in RFC\ 2373.
- .P
- .SH "RETURN VALUE"
- The
- \fIinet_ntop\fR()
- function shall return a pointer to the buffer containing the text
- string if the conversion succeeds, and NULL otherwise, and set
- .IR errno
- to indicate the error.
- .P
- The
- \fIinet_pton\fR()
- function shall return 1 if the conversion succeeds, with the address
- pointed to by
- .IR 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
- .IR errno
- set to
- .BR [EAFNOSUPPORT]
- if the
- .IR af
- argument is unknown.
- .SH ERRORS
- The
- \fIinet_ntop\fR()
- and
- \fIinet_pton\fR()
- functions shall fail if:
- .TP
- .BR EAFNOSUPPORT
- .br
- The
- .IR af
- argument is invalid.
- .TP
- .BR ENOSPC
- The size of the
- \fIinet_ntop\fR()
- result buffer is inadequate.
- .LP
- .IR "The following sections are informative."
- .SH "EXAMPLES"
- None.
- .SH "APPLICATION USAGE"
- None.
- .SH "RATIONALE"
- None.
- .SH "FUTURE DIRECTIONS"
- None.
- .SH "SEE ALSO"
- The Base Definitions volume of POSIX.1\(hy2017,
- .IR "\fB<arpa_inet.h>\fP"
- .\"
- .SH 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 .
- .PP
- 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 .