std.Io.Threaded: fix netLookup for Windows

* respect address family option
* fix port number using wrong buffer
This commit is contained in:
Andrew Kelley 2025-10-27 20:23:21 -07:00
parent 030ddc7952
commit 30448d92af

View File

@ -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,