inet_pton(3)inet_pton(3)NAMEinet_pton - Convert a text string to a numeric address
SYNOPSIS
#include <arpa/inet.h>
int inet_pton(
int af,
const char *src,
void *dst );
LIBRARY
Standard C Library (libc)
PARAMETERS
Specifies the address family. Valid values are AF_INET for an Internet
Protocol Version 4 (IPv4) address and AF_INET6 for an IPv6 address.
Points to the address text string to be converted. Points to a buffer
that is to contain the numeric address.
DESCRIPTION
The use of this routine is deprecated. Use the getaddrinfo(3) routine
instead; it is also protocol-independent.
The inet_pton() function converts a text string to a numeric value in
Internet network-byte order.
If the af parameter is AF_INET, the function accepts a string in the
standard IPv4 dotted-decimal form:
ddd.ddd.ddd.ddd
In this format, ddd is a one to three digit decimal number between 0
and 255.
If the af parameter is AF_INET6, the function accepts a string in the
following form:
x:x:x:x:x:x:x:x
In this format, x is hexadecimal value of a 16-bit piece of the
address.
IPv6 addresses can contain long strings of zero (0) bits. To make it
easier to write these addresses, you can use double colon characters
(::) one time in an address to represent 1 or more 16-bit groups of
zeros.
For mixed IPv4 and IPv6 environments, the following form is also
accepted:
x:x:x:x:x:x:ddd.ddd.ddd.ddd
In this form, x is hexadecimal value of a 16-bit piece of the address
and ddd is a one to three digit decimal value between 0 and 255 that
represents the IPv4 address. See RFC 2373 for more information on IPv6
addressing formats.
The calling application is responsible for ensuring that the buffer
referred to by the dst parameter is large enough to hold the numeric
address. AF_INET addresses require 4 bytes and AF_INET6 addresses
require 16 bytes.
RETURN VALUES
Upon successful completion, the inet_pton() function returns 1. If the
input string is not a valid IPv4 dotted-decimal string or a valid IPv6
address string, the function returns 0. If any other error occurs, the
function returns -1.
ERRORS
If the inet_pton() routine call fails, errno is set to one of the fol‐
lowing values: The address family specified in the af parameter is
unknown.
SEE ALSO
Functions: getaddrinfo(3), inet_ntop(3).
RFC 2373, IP Version 6 Addressing Architecture
Network Programmer's Guide
inet_pton(3)