ares_inet_pton(3)

ARES_INET_PTON(3) Library Functions Manual ARES_INET_PTON(3)

NAME

ares_inet_pton - convert an IPv4 or IPv6 address from text to binary form

SYNOPSIS

#include <ares.h>
int ares_inet_pton(int af, const char *src, void *dst);

DESCRIPTION

This is a portable version of the commonly available inet_pton. It behaves the same for AF_INET6, and for AF_INET it additionally accepts the legacy forms described below.

The ares_inet_pton() function converts the address in its standard text presentation form into its numeric binary form. The af argument shall specify the family of the address. The AF_INET and AF_INET6 address families shall be supported. The src argument points to the string being passed in. The 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).

The src argument must be an address, not a network: a "/bits" prefix length suffix (CIDR notation) is not accepted and the function returns 0 for such input. On success, the whole address (4 bytes for AF_INET, 16 bytes for AF_INET6) is always written to dst. Versions of c-ares before 1.34.9 accepted a prefix length here.

Unlike POSIX inet_pton, AF_INET also accepts shortened forms such as "10.1" and hexadecimal forms such as "0x0a000001". Octets that are not given are set to zero, so "10.1" is 10.1.0.0.

It returns 1 if the address was valid for the specified address family, or 0 if the address was not parseable in the specified address family, or -1 if the address family is not supported (in which case errno will have been set to EAFNOSUPPORT).

SEE ALSO

ares_init(3), ares_inet_ntop(3)

AVAILABILITY

made properly publicly available in c-ares for real in version 1.10.0

17 Feb 2013