From 30448d92af596724dc227c96803961bc41de9253 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 27 Oct 2025 20:23:21 -0700 Subject: [PATCH] std.Io.Threaded: fix netLookup for Windows * respect address family option * fix port number using wrong buffer --- lib/std/Io/Threaded.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 81b3d55a1f..9becb59a7a 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -4635,13 +4635,17 @@ fn netLookupFallible( var port_buffer_wide: [8]u16 = undefined; const port = std.fmt.bufPrint(&port_buffer, "{d}", .{options.port}) catch unreachable; // `port_buffer` is big enough for decimal u16. - for (port, port_buffer[0..port.len]) |byte, *wide| wide.* = byte; + for (port, port_buffer_wide[0..port.len]) |byte, *wide| + wide.* = std.mem.nativeToLittle(u16, byte); port_buffer_wide[port.len] = 0; const port_w = port_buffer_wide[0..port.len :0]; const hints: ws2_32.ADDRINFOEXW = .{ .flags = .{ .NUMERICSERV = true }, - .family = posix.AF.UNSPEC, + .family = if (options.family) |f| switch (f) { + .ip4 => posix.AF.INET, + .ip6 => posix.AF.INET6, + } else posix.AF.UNSPEC, .socktype = posix.SOCK.STREAM, .protocol = posix.IPPROTO.TCP, .canonname = null,