|
Packit |
7cfc04 |
'\" et
|
|
Packit |
7cfc04 |
.TH INET_NTOP "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH PROLOG
|
|
Packit |
7cfc04 |
This manual page is part of the POSIX Programmer's Manual.
|
|
Packit |
7cfc04 |
The Linux implementation of this interface may differ (consult
|
|
Packit |
7cfc04 |
the corresponding Linux manual page for details of Linux behavior),
|
|
Packit |
7cfc04 |
or the interface may not be implemented on Linux.
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
inet_ntop,
|
|
Packit |
7cfc04 |
inet_pton
|
|
Packit |
7cfc04 |
\(em convert IPv4 and IPv6 addresses between binary and text form
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
#include <arpa/inet.h>
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
const char *inet_ntop(int \fIaf\fP, const void *restrict \fIsrc\fP,
|
|
Packit |
7cfc04 |
char *restrict \fIdst\fP, socklen_t \fIsize\fP);
|
|
Packit |
7cfc04 |
int inet_pton(int \fIaf\fP, const char *restrict \fIsrc\fP, void *restrict \fIdst\fP);
|
|
Packit |
7cfc04 |
.fi
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIinet_ntop\fR()
|
|
Packit |
7cfc04 |
function shall convert a numeric address into a text string suitable
|
|
Packit |
7cfc04 |
for presentation. The
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument shall specify the family of the address. This can be AF_INET
|
|
Packit |
7cfc04 |
or AF_INET6.
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR src
|
|
Packit |
7cfc04 |
argument points to a buffer holding an IPv4 address if the
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument is AF_INET,
|
|
Packit |
7cfc04 |
or an IPv6 address if the
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument is AF_INET6;
|
|
Packit |
7cfc04 |
the address must be in network byte order. The
|
|
Packit |
7cfc04 |
.IR dst
|
|
Packit |
7cfc04 |
argument points to a buffer where the function stores the resulting
|
|
Packit |
7cfc04 |
text string; it shall not be NULL. The
|
|
Packit |
7cfc04 |
.IR size
|
|
Packit |
7cfc04 |
argument specifies the size of this buffer, which shall be large enough
|
|
Packit |
7cfc04 |
to hold the text string (INET_ADDRSTRLEN characters for IPv4,
|
|
Packit |
7cfc04 |
INET6_ADDRSTRLEN characters for IPv6).
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIinet_pton\fR()
|
|
Packit |
7cfc04 |
function shall convert an address in its standard text presentation
|
|
Packit |
7cfc04 |
form into its numeric binary form. The
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument shall specify the family of the address. The AF_INET
|
|
Packit |
7cfc04 |
and AF_INET6
|
|
Packit |
7cfc04 |
address families shall be supported. The
|
|
Packit |
7cfc04 |
.IR src
|
|
Packit |
7cfc04 |
argument points to the string being passed in. The
|
|
Packit |
7cfc04 |
.IR dst
|
|
Packit |
7cfc04 |
argument points to a buffer into which the function stores the numeric
|
|
Packit |
7cfc04 |
address; this shall be large enough to hold the numeric address (32 bits
|
|
Packit |
7cfc04 |
for AF_INET,
|
|
Packit |
7cfc04 |
128 bits for AF_INET6).
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument of
|
|
Packit |
7cfc04 |
\fIinet_pton\fR()
|
|
Packit |
7cfc04 |
is AF_INET, the
|
|
Packit |
7cfc04 |
.IR src
|
|
Packit |
7cfc04 |
string shall be in the standard IPv4 dotted-decimal form:
|
|
Packit |
7cfc04 |
.sp
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
.nf
|
|
Packit |
7cfc04 |
\fB
|
|
Packit |
7cfc04 |
ddd.ddd.ddd.ddd
|
|
Packit |
7cfc04 |
.fi \fR
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
where
|
|
Packit |
7cfc04 |
.BR \(dqddd\(dq
|
|
Packit |
7cfc04 |
is a one to three digit decimal number between 0 and 255 (see
|
|
Packit |
7cfc04 |
.IR "\fIinet_addr\fR\^(\|)").
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIinet_pton\fR()
|
|
Packit |
7cfc04 |
function does not accept other formats (such as the octal numbers,
|
|
Packit |
7cfc04 |
hexadecimal numbers, and fewer than four numbers that
|
|
Packit |
7cfc04 |
\fIinet_addr\fR()
|
|
Packit |
7cfc04 |
accepts).
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
If the
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument of
|
|
Packit |
7cfc04 |
\fIinet_pton\fR()
|
|
Packit |
7cfc04 |
is AF_INET6, the
|
|
Packit |
7cfc04 |
.IR src
|
|
Packit |
7cfc04 |
string shall be in one of the following standard IPv6 text forms:
|
|
Packit |
7cfc04 |
.IP " 1." 4
|
|
Packit |
7cfc04 |
The preferred form is
|
|
Packit |
7cfc04 |
.BR \(dqx:x:x:x:x:x:x:x\(dq ,
|
|
Packit |
7cfc04 |
where the
|
|
Packit |
7cfc04 |
.BR 'x' s
|
|
Packit |
7cfc04 |
are the hexadecimal values of the eight 16-bit pieces of the address.
|
|
Packit |
7cfc04 |
Leading zeros in individual fields can be omitted, but there shall be at
|
|
Packit |
7cfc04 |
least one numeral in every field.
|
|
Packit |
7cfc04 |
.IP " 2." 4
|
|
Packit |
7cfc04 |
A string of contiguous zero fields in the preferred form can be shown
|
|
Packit |
7cfc04 |
as
|
|
Packit |
7cfc04 |
.BR \(dq::\(dq .
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR \(dq::\(dq
|
|
Packit |
7cfc04 |
can only appear once in an address. Unspecified addresses (\c
|
|
Packit |
7cfc04 |
.BR \(dq0:0:0:0:0:0:0:0\(dq )
|
|
Packit |
7cfc04 |
may be represented simply as
|
|
Packit |
7cfc04 |
.BR \(dq::\(dq .
|
|
Packit |
7cfc04 |
.IP " 3." 4
|
|
Packit |
7cfc04 |
A third form that is sometimes more convenient when dealing with a
|
|
Packit |
7cfc04 |
mixed environment of IPv4 and IPv6 nodes is
|
|
Packit |
7cfc04 |
.BR \(dqx:x:x:x:x:x:d.d.d.d\(dq ,
|
|
Packit |
7cfc04 |
where the
|
|
Packit |
7cfc04 |
.BR 'x' s
|
|
Packit |
7cfc04 |
are the hexadecimal values of the six high-order 16-bit pieces of the
|
|
Packit |
7cfc04 |
address, and the
|
|
Packit |
7cfc04 |
.BR 'd' s
|
|
Packit |
7cfc04 |
are the decimal values of the four low-order 8-bit pieces of the
|
|
Packit |
7cfc04 |
address (standard IPv4 representation).
|
|
Packit |
7cfc04 |
.TP 10
|
|
Packit |
7cfc04 |
.BR Note:
|
|
Packit |
7cfc04 |
A more extensive description of the standard representations of IPv6
|
|
Packit |
7cfc04 |
addresses can be found in RFC\ 2373.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
.SH "RETURN VALUE"
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIinet_ntop\fR()
|
|
Packit |
7cfc04 |
function shall return a pointer to the buffer containing the text
|
|
Packit |
7cfc04 |
string if the conversion succeeds, and NULL otherwise, and set
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
to indicate the error.
|
|
Packit |
7cfc04 |
.P
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIinet_pton\fR()
|
|
Packit |
7cfc04 |
function shall return 1 if the conversion succeeds, with the address
|
|
Packit |
7cfc04 |
pointed to by
|
|
Packit |
7cfc04 |
.IR dst
|
|
Packit |
7cfc04 |
in network byte order. It shall return 0 if the input is not a valid
|
|
Packit |
7cfc04 |
IPv4 dotted-decimal string
|
|
Packit |
7cfc04 |
or a valid IPv6 address string,
|
|
Packit |
7cfc04 |
or \(mi1 with
|
|
Packit |
7cfc04 |
.IR errno
|
|
Packit |
7cfc04 |
set to
|
|
Packit |
7cfc04 |
.BR [EAFNOSUPPORT]
|
|
Packit |
7cfc04 |
if the
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument is unknown.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
\fIinet_ntop\fR()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
\fIinet_pton\fR()
|
|
Packit |
7cfc04 |
functions shall fail if:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR EAFNOSUPPORT
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.IR af
|
|
Packit |
7cfc04 |
argument is invalid.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR ENOSPC
|
|
Packit |
7cfc04 |
The size of the
|
|
Packit |
7cfc04 |
\fIinet_ntop\fR()
|
|
Packit |
7cfc04 |
result buffer is inadequate.
|
|
Packit |
7cfc04 |
.LP
|
|
Packit |
7cfc04 |
.IR "The following sections are informative."
|
|
Packit |
7cfc04 |
.SH "EXAMPLES"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "APPLICATION USAGE"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "RATIONALE"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "FUTURE DIRECTIONS"
|
|
Packit |
7cfc04 |
None.
|
|
Packit |
7cfc04 |
.SH "SEE ALSO"
|
|
Packit |
7cfc04 |
The Base Definitions volume of POSIX.1\(hy2008,
|
|
Packit |
7cfc04 |
.IR "\fB<arpa_inet.h>\fP"
|
|
Packit |
7cfc04 |
.SH COPYRIGHT
|
|
Packit |
7cfc04 |
Portions of this text are reprinted and reproduced in electronic form
|
|
Packit |
7cfc04 |
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
|
|
Packit |
7cfc04 |
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Packit |
7cfc04 |
Specifications Issue 7, Copyright (C) 2013 by the Institute of
|
|
Packit |
7cfc04 |
Electrical and Electronics Engineers, Inc and The Open Group.
|
|
Packit |
7cfc04 |
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
|
|
Packit |
7cfc04 |
event of any discrepancy between this version and the original IEEE and
|
|
Packit |
7cfc04 |
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
Packit |
7cfc04 |
is the referee document. The original Standard can be obtained online at
|
|
Packit |
7cfc04 |
http://www.unix.org/online.html .
|
|
Packit |
7cfc04 |
|
|
Packit |
7cfc04 |
Any typographical or formatting errors that appear
|
|
Packit |
7cfc04 |
in this page are most likely
|
|
Packit |
7cfc04 |
to have been introduced during the conversion of the source files to
|
|
Packit |
7cfc04 |
man page format. To report such errors, see
|
|
Packit |
7cfc04 |
https://www.kernel.org/doc/man-pages/reporting_bugs.html .
|