Re: IPv6-capable hostname lookup in ext/standard
| From: | Xavier Leune | Date: | Fri, 13 Nov 2026 20:04:43 +0000 |
| Subject: | Re: IPv6-capable hostname lookup in ext/standard | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-133098@lists.php.net to get a copy of this message | ||
Hi David,
Le ven. 13 nov. 2026 à 18:46, David CARLIER <devnexen@gmail.com> a écrit :
> 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.
>
Great idea. A few questions:
- do you plan to return an empty array when there is no failure but no
matching record, or false ?
- why only A and AAAA? Other records are useful too, especially SVC
- do you think you may wrap the syscall with a timeout somehow ? I’m not
sure it’s possible due to how the kernel handles it but it would be great
- may you add the ip of the dns server to reach ?
With all that, the dns resolution would be much more useful on php.
Thanks,
Xavier
>