svcadm(1M)을 검색하려면 섹션에서 1M 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
inet_pton(3c)
Standard C Library Functions inet(3C)
NAME
inet, inet6, inet_ntop, inet_pton, inet_aton, inet_addr, inet_network,
inet_makeaddr, inet_lnaof, inet_netof, inet_ntoa - Internet address
manipulation
SYNOPSIS
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
const char *inet_ntop(int af, const void *addr, char *cp,
socklen_t size);
int inet_pton(int af, const char *cp, void *addr);
int inet_aton(const char *cp, struct in_addr *addr);
in_addr_t inet_addr(const char *cp);
in_addr_t inet_network(const char *cp);
struct in_addr inet_makeaddr(in_addr_t net, in_addr_t lna);
in_addr_t inet_lnaof(struct in_addr in);
in_addr_t inet_netof(struct in_addr in);
char *inet_ntoa(struct in_addr in);
DESCRIPTION
These functions manipulate IP addresses in various ways, including
transformations between string representations and numeric address
forms. The inet_ntop() and inet_pton() functions can manipulate both
IPv4 and IPv6 addresses, and are thus recommended over their older
IPv4-only counterparts. The inet_aton(), inet_addr(), inet_network(),
inet_makeaddr(), inet_lnaof(), inet_netof(), and inet_ntoa() functions
can only manipulate IPv4 addresses.
The inet_ntop() function converts a numeric address into a string suit‐
able for presentation. The af argument specifies the family of the
address which can be AF_INET or AF_INET6. The addr argument points to a
buffer that holds an IPv4 address if the af argument is AF_INET. The
addr argument points to a buffer that holds an IPv6 address if the af
argument is AF_INET6. The address must be in network byte order. The cp
argument points to a buffer where the function stores the resulting
string. The application must specify a non-NULL cp argument. The size
argument specifies the size of this buffer. For IPv6 addresses, the
buffer must be at least 46-octets. For IPv4 addresses, the buffer must
be at least 16-octets. To allow applications to easily declare buffers
of the proper size to store IPv4 and IPv6 addresses in string form, the
following two constants are defined in <netinet/in.h>:
#define INET_ADDRSTRLEN 16
#define INET6_ADDRSTRLEN 46
The inet_pton() function converts the standard text presentation form
of an address into its numeric binary form. The af argument specifies
the family of the address. Currently, the AF_INET and AF_INET6 address
families are supported. The cp argument points to the string being
passed in. The addr argument points to a buffer where the function
stores the numeric address. The calling application must ensure that
the buffer referred to by addr is large enough to hold the numeric
address, at least 4 bytes for AF_INET or 16 bytes for AF_INET6.
The inet_aton(), inet_addr(), and inet_network() functions interpret
character strings that represent numbers expressed in the IPv4 standard
'.' notation, returning numbers suitable for use as IPv4 addresses and
IPv4 network numbers, respectively. The inet_makeaddr() function uses
an IPv4 network number and a local network address to construct an IPv4
address. The inet_netof() and inet_lnaof() functions break apart IPv4
host addresses, then return the network number and local network
address, respectively.
The inet_addr() function has been obsoleted by inet_aton(), which in
turn has been superseded by inet_pton().
The inet_ntoa() function returns a pointer to a string in the base 256
notation d.d.d.d. See the following section on IPv4 Addresses.
Internet addresses are returned in network order, bytes ordered from
left to right. Network numbers and local address parts are returned as
machine format integer values.
IPv6 Addresses
There are three conventional forms for representing IPv6 addresses as
strings:
1. 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. For example:
1080:0:0:0:8:800:200C:417A
It is not necessary to write the leading zeros in an indi‐
vidual field. There must be at least one numeral in every
field, except when the special syntax described in the fol‐
lowing is used.
2. It is common for addresses to contain long strings of zero
bits in some methods used to allocate certain IPv6 address
styles. A special syntax is available to compress the zeros.
The use of "::" indicates multiple groups of 16 bits of
zeros. The :: may only appear once in an address. The :: can
also be used to compress the leading and trailing zeros in
an address. For example:
1080::8:800:200C:417A
3. The alternative form x:x:x:x:x:x:d.d.d.d is sometimes more
convenient when dealing with a mixed environment of IPv4 and
IPv6 nodes. The x's in this form represent the hexadecimal
values of the six high-order 16-bit pieces of the address.
The d's represent the decimal values of the four low-order
8-bit pieces of the standard IPv4 address. For example:
::FFFF:129.144.52.38
::129.144.52.38
The ::FFFF:d.d.d.d and ::d.d.d.d pieces are the general
forms of an IPv4-mapped IPv6 address and an IPv4-compatible
IPv6 address.
The IPv4 portion must be in the d.d.d.d form. The following
forms are invalid:
::FFFF:d.d.d
::FFFF:d.d
::d.d.d
::d.d
The ::FFFF:d form is a valid but unconventional representa‐
tion of the IPv4-compatible IPv6 address ::255.255.0.d.
The ::d form corresponds to the general IPv6 address
0:0:0:0:0:0:0:d.
IPv4 Addresses
Values specified using '.' notation take one of the following forms:
d.d.d.d
d.d.d
d.d
d
When four parts are specified, each part is interpreted as a byte of
data and assigned from left to right to the four bytes of an IPv4
address.
When a three-part address is specified, the last part is interpreted as
a 16-bit quantity and placed in the right most two bytes of the network
address. The three part address format is convenient for specifying
Class B network addresses such as 128.net.host.
When a two-part address is supplied, the last part is interpreted as a
24-bit quantity and placed in the right most three bytes of the network
address. The two part address format is convenient for specifying Class
A network addresses such as net.host.
When only one part is given, the value is stored directly in the net‐
work address without any byte rearrangement.
With the exception of inet_pton(), numbers supplied as parts in '.'
notation may be decimal, octal, or hexadecimal, as specified in C lan‐
guage. For example, a leading 0x or 0X implies hexadecimal. A leading 0
implies octal. Otherwise, the number is interpreted as decimal.
For IPv4 addresses, inet_pton() accepts only a string in standard IPv4
dot notation:
d.d.d.d
Each number has one to three digits with a decimal value between 0 and
255.
RETURN VALUES
The inet_aton() function returns nonzero if the address is valid, 0 if
the address is invalid.
The inet_ntop() function returns a pointer to the buffer that contains
a string if the conversion succeeds. Otherwise, NULL is returned. Upon
failure, errno is set to EAFNOSUPPORT if the af argument is invalid or
ENOSPC if the size of the result buffer is inadequate.
The inet_pton() function returns 1 if the conversion succeeds, 0 if the
input is not a valid IPv4 dotted-decimal string or a valid IPv6 address
string. The function returns −1 with errno set to EAFNOSUPPORT if the
af argument is unknown.
The value INADDR_NONE, which is equivalent to (in_addr_t)(-1), is
returned by inet_addr() and inet_network() for malformed requests.
The functions inet_netof() and inet_lnaof() break apart IPv4 host
addresses, returning the network number and local network address part,
respectively.
The function inet_ntoa() returns a pointer to a string in the base 256
notation d.d.d.d, described in the section on IPv4 addresses.
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
TRIBUTE VALUE _ Interface StabilitySee below. _ MT-LevelSafe
The inet_ntop(), inet_pton(), inet_aton(), inet_addr(), and inet_ntoa()
functions are Committed. The inet_lnaof(), inet_makeaddr(),
inet_netof(), and inet_network() functions are Committed (Obsolete).
SEE ALSO
byteorder(3C), getaddrinfo(3C), getnetbyname(3C), inet.h(3HEAD),
hosts(5), networks(5), attributes(7)
Gilligan, R. RFC 3493, Basic Socket Interface Extensions for IPv6. Net‐
work Working Group. February 2003. https://tools.ietf.org/html/rfc3493
NOTES
The return value from inet_ntoa() points to a buffer which is overwrit‐
ten on each call. This buffer is implemented as thread-specific data in
multithreaded applications.
IPv4-mapped addresses are not recommended.
BUGS
The problem of host byte ordering versus network byte ordering is con‐
fusing. See the byteorder(3C) man page for functions to handle byte
ordering.
HISTORY
The inet_aton() function was added to Oracle Solaris in the Solaris 10
4/08 (Update 5) release.
The inet_ntop() and inet_pton() functions were added to Oracle Solaris
in the Solaris 8 release.
The rest of the functions described in this man page have been present
since the initial release of Solaris.
Oracle Solaris 11.4 2 Feb 2021 inet(3C)