Skip to content

arg: reuse hostname addresses across port lists - #421

Merged
jiegec merged 2 commits into
masterfrom
fix/hostname-port-families-followup
Nov 29, 2026
Merged

jiegec merged 2 commits into
masterfrom
fix/hostname-port-families-followup

Conversation

@jiegec

@jiegec jiegec commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #416.

Changes

  • Cache the IPv6 and IPv4 hostent address lists once per host name instead of re-resolving the name for every port in -i@host:port1,port2,.... For N ports this reduces resolver calls from about 2N to 2. The cache also avoids the stale n.a/NULL hostent path for names that resolve only to IPv6.
  • Raise MAXNWAD from 100 to 200 so a dual-stack name with 100 comma-separated ports still fits the address chain (each port now needs an entry per family).
  • Move the multi-port family regression out of tests/case-23-multi-address-hostname.bash into tests/case-25-hostname-port-families.bash, so its PASS/SKIP state is visible. case-23 was reported as SKIP on CI when the configured host name had a single address, hiding the new test.
  • Use the loopback addresses returned by getaddrinfo() instead of hard-coded 127.0.0.1/::1, use explicit FAIL:/sys.exit(1) instead of assert, and skip only when a dual-family localhost is genuinely unavailable.
  • Make case-23 count addresses across families and fall back to localhost so it no longer skips on systems whose host name has a single address.

Testing

  • All 16 dialect-neutral tests pass with 0 SKIP, including new case-25.
  • case-25 fails against the pre-arg: search both hostname families for each port #416 arg.c (found={'3'}, expected={'3','4'}) and passes with this branch.
  • Local checks cover TCP and UDP, both port orders, leading port 0, port ranges, no port, -i4/-i6 prefixes, separate -i4/-i6, repeated -i, and unknown hosts.
  • ASAN build reports no leaks on the success and error paths.
  • MAXNWAD check: a host name with one address per family accepts 100 comma-separated ports and rejects 101; this host's localhost (two IPv4 addresses plus one IPv6) accepts 66 and rejects 67.

Addresses the review follow-ups from #416.

A host name that resolves to both IPv6 and IPv4 is searched for every port in a comma-separated list.  The fix for that in #416 re-resolved the name for each port because gethostbyname2() returns static storage that the IPv4 fallback overwrites.

Copy the IPv6 and IPv4 address lists into private storage and reuse them for every port.  This keeps the per-port family search while reducing the resolver calls from about 2N to 2 for N ports.

The cache also avoids the stale n.a / NULL hostent path for names that resolve only to IPv6, and MAXNWAD is raised so a dual-stack name with 100 comma-separated ports still fits the address chain.
Move the port-list family regression out of case-23 into its own case-25.  case-23 is reported as SKIP on CI when the configured host name has only one address, which hid the new test's PASS.  The new case uses the loopback addresses returned by getaddrinfo() instead of hard-coded ones, reports failures with FAIL:/sys.exit(1) instead of an assert, and skips only if a dual-family localhost is unavailable.

Make case-23 count addresses across families and fall back to localhost, so it runs on systems whose host name has a single address.
@jiegec
jiegec merged commit 2f88b55 into master Nov 29, 2026
29 checks passed
@jiegec
jiegec deleted the fix/hostname-port-families-followup branch November 29, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant