ARES_INET_PTON(3)
π ARES_INET_PTON(3) π
okay so bestie, welcome to ares_inet_pton β a little function from the Library Functions Manual section of the c-ares world, and honestly she's iconic for reasons we're about to get into π
β¨ NAME β¨
ares_inet_pton β converts an IPv4 or IPv6 address from text form into binary form. literally just glow-up-ifying your string into bytes, no cap π
πΈ SYNOPSIS πΈ
#include <ares.h>
int ares_inet_pton(int af, const char *src, void *dst);
π¦ DESCRIPTION π¦
so this is the portable version of the inet_pton you already know and love. for AF_INET6 she behaves exactly the same β no notes, same energy. but for AF_INET she's got a little extra, and she's gonna accept the legacy forms described below π (yes those ones, we'll get there).
The ares_inet_pton() function takes the address sitting in its standard text presentation form and converts it into its numeric binary form. The af argument shall specify the family of the address β and AF_INET and AF_INET6 shall be the supported ones. The src argument points to the string being passed in. The dst argument points to a buffer where the function stores the numeric address, and bestie listen: this buffer shall be big enough to hold the numeric address β that's 32 bits for AF_INET and 128 bits for AF_INET6. do not skimp on the buffer, I'm begging π
The src argument must be an address, not a network. A "/bits" prefix length suffix (CIDR notation, you know the vibe) is not accepted, and the function just returns 0 for that kind of input. π«
On success, the whole address β 4 bytes for AF_INET, 16 bytes for AF_INET6 β is always written to dst. And here's a little lore drop for you: versions of c-ares before 1.34.9 accepted a prefix length here. we don't do that anymore, she's moved on π
Unlike POSIXinet_pton,AF_INETalso accepts shortened forms such as10.1and hexadecimal forms such as0x0a000001. Octets that are not given are set to zero, so10.1is10.1.0.0. so generous of her honestly π
β RETURN VALUES (the vibe check) β
she returns:
1β the address was valid for the specified address family. slay, it worked π0β the address was not parseable in the specified address family. not her fault, the string was giving chaos π-1β the address family is not supported (and in that caseerrnowill have been set toEAFNOSUPPORT). devious of you to even ask π
π₯ SEE ALSO π₯
(the round trip is real, iykyk π)
π AVAILABILITY π
made properly publicly available in c-ares for real in version 1.10.0. no cap, she's been out here since then π«Ά
okay bestie that's the whole page β¨ ngl this one's a lil legend: she's from 17 Feb 2013, she lives in the Library Functions Manual as ARES_INET_PTON(3), and she's serving portable-binary-conversion realness. go forth and parse responsibly πππ¦
π¦ where this page comes from
- alpine 3.22: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.23: c-ares-doc 1.34.9-r0 Β· MIT
- alpine 3.24: c-ares-doc 1.34.9-r0 Β· MIT
- arch rolling: c-ares 1.34.9-1 Β· MIT
- centos-stream 10: c-ares-devel 1.34.9-1.el10 Β· MIT
- nixos 26.05: c-ares 1.34.9
- π the page's license: MIT
- Copyright (C) 2013 by Daniel Stenberg
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms