---
name: ipv6-name-resolution
description: >
  Use when resolving hostnames, opening connections, replacing gethostbyname or
  getByName, or touching language socket helpers. Enforces full-list getaddrinfo-style
  resolution, Happy Eyeballs, and dual-stack or IPv6-only safe clients in Python, Go,
  Java, and Node.
---

# IPv6 name resolution

## Instructions

1. Use a family-agnostic API that returns the **full** candidate set (`getaddrinfo` with `AF_UNSPEC`, or language equivalent).
2. Iterate **all** candidates (or use OS/library Happy Eyeballs). Do not connect to only the first A or AAAA.
3. Prefer the platform Happy Eyeballs implementation over a custom race. If custom is unavoidable, delay the other family so the preferred family gets a head start (RFC 8305).
4. On total failure, prefer reporting useful multi-candidate errors, not only the first attempt.
5. For numeric literals, parse with `inet_pton` (or equivalent); when input may be name or literal, use `getaddrinfo` or try literal then DNS.
6. After resolving, load `ipv6-destination-selection` if multiple same-family addresses need spreading.

## Language defaults

| Language | Prefer | Avoid |
| --- | --- | --- |
| Python | `socket.getaddrinfo()`; iterate all | `gethostbyname`, `gethostbyname_ex`, `inet_aton`/`inet_ntoa` for dual-stack |
| Go | `net.Dialer` (Happy Eyeballs); `LookupIP`/`LookupIPAddr` full list | Assuming a single IP |
| Java | `InetAddress.getAllByName()` | `getByName()`; unchecked `preferIPv4Stack` |
| Node.js | `dns.lookup`/`promises.lookup` with `{ all: true }`; `net.connect` `autoSelectFamily` | Default single-address `lookup` |

## AAAA / A filtering in stub resolvers

Per [draft-ietf-v6ops-aaaa-filtering](https://datatracker.ietf.org/doc/draft-ietf-v6ops-aaaa-filtering/), a stub resolver **MAY** skip the A or AAAA query when it believes the host has no usable connectivity for that family (routing-table or address-based detection, similar in spirit to `AI_ADDRCONFIG`). Platforms with Happy Eyeballs can still query both without much user impact.

For application code:

1. Do not assume both A and AAAA were queried. The candidate list may already be filtered.
2. Still try **every** address returned. Filtering is optional; poorly written "first address only" clients fail either way.
3. Mis-detected connectivity (link-local-only routes, split VPN, private nets without a default) can hide AAAA or A. Prefer route/address based detection over probing a hard-coded public IP.
4. NAT64/DNS64 without CLAT: suppressing A can be correct; CLAT or API translators that need A must not suppress A when NAT64 is present.
5. Runtime flags that force IPv4 (`ipv6-runtime-config`) compound filtering: the OS may return AAAA and the JVM may still prefer IPv4.

## Gotchas

- `gethostbyname` / one-address APIs never return IPv6 even when AAAA exists.
- libc may reorder results (RFC 6724); you still need every element.
- Java and some runtimes have their own resolver preference independent of `/etc/gai.conf`. Load `ipv6-runtime-config` for JVM and process flags.
- An `/etc/resolv.conf` with only IPv6 nameservers can break runtimes that assume an IPv4 resolver path. Qualify each runtime on dual-stack and IPv6-only hosts.

## Example (Python)

```python
infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM)
# Prefer stdlib/OS Happy Eyeballs when available; otherwise try each info in order.
```

## Sibling skills

- `ipv6-ready-coding`
- `ipv6-destination-selection`
- `ipv6-runtime-config`
- `ipv6-code-review`

## Source

- Hub: https://www.peachymango.org/ipv6
- Draft anchors: `#name-resolution`, `#runtime-resolution`, `#language-runtimes`
- https://datatracker.ietf.org/doc/draft-martin-deploying-ipv6-data-center/
- https://datatracker.ietf.org/doc/draft-ietf-v6ops-aaaa-filtering/
