From cb7c6e391872d2922a688c77def805883b69eba8 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 1 Jun 2026 16:48:12 -0700 Subject: [PATCH] std.Io.Threaded: respect options.family in netLookup Previously `AF_UNSPEC` was passed unconditionally to `getaddrinfo`. This specifies `AF_INET` or `AF_INET6` depending on the value of HostName.LookupOptions.family. `AF_UNSPEC` is still set by default (when family == null). --- lib/std/Io/Threaded.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 7a4e2640376345437afa5721b83f8ddb0d99453f..555ff219d308cba7647a791bf770b28b6895c6d1 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -13923,9 +13923,14 @@ fn netLookupFallible( var port_buffer: [8]u8 = undefined; const port_c = std.fmt.bufPrintSentinel(&port_buffer, "{d}", .{options.port}, 0) catch unreachable; + const family: i32 = if (options.family) |f| switch (f) { + .ip4 => posix.AF.INET, + .ip6 => posix.AF.INET6, + } else posix.AF.UNSPEC; + const hints: posix.addrinfo = .{ .flags = .{ .CANONNAME = options.canonical_name_buffer != null, .NUMERICSERV = true }, - .family = posix.AF.UNSPEC, + .family = family, .socktype = posix.SOCK.STREAM, .protocol = posix.IPPROTO.TCP, .canonname = null, -- 2.54.0