IPv6-capable hostname lookup in ext/standard

From: Date: Fri, 13 Nov 2026 17:44:35 +0000
Subject: IPv6-capable hostname lookup in ext/standard
Groups: php.internals 
Request: Send a blank email to internals+get-133097@lists.php.net to get a copy of this message
Hi ! GH-25446 asks for a way to resolve a hostname to IPv6 addresses. ext/standard cannot do that through the system resolver today: - gethostbyname() and gethostbynamel() are IPv4-only by documentation. Changing their return values would break callers expecting a dotted quad. - dns_get_record($host, DNS_AAAA) queries DNS directly and skips /etc/hosts/nsswitch, so localhost and hosts-file entries do not resolve. - socket_addrinfo_lookup() does it right but needs ext/sockets, and you have to unpack its AddressInfo objects with socket_addrinfo_explain(). I'd like to add a new function for master, something like: function gethostaddresses(string $hostname, int $family = DNS_A | DNS_AAAA): array|false {} It returns the address strings in getaddrinfo() order, or false on failure. It goes through the system resolver like stream connections do. $family reuses DNS_A/DNS_AAAA, since the AF_* constants live in ext/sockets. php_network_getaddresses() already wraps getaddrinfo(), so the change is small and fits with the resolver cleanup in GH-15555. Kind of open questions: 1. Naming: a new function, or a new parameter on gethostbynamel()? 2. Should $family take the DNS_* constants, or should ext/standard get its own constants? Unless there are objections, I'll open a PR in the coming days. Cheers.

« previous php.internals (#133097) next »