commit a0aba69c1143073aa06f19f759dabe4aa58454d1 (tree)
parent 908970df1c9a509c73d24a566292db2fba049498
Author: Andrew Kelley <andrew@ziglang.org>
Date: Wed, 27 May 2026 16:36:12 -0700
std.Io: fix DNS lookup
The DNS lookup code incorrectly passed ip6_only=true when it intended to
pass ip6_only=false. The other bug fix in
be7065f7f541f3eb1dcb64869ef1fed716645cd1 revealed this additional bug.
Diffstat:
4 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/lib/std/Io/Kqueue.zig b/lib/std/Io/Kqueue.zig
@@ -1401,9 +1401,9 @@ fn openSocketPosix(
};
errdefer closeFd(socket_fd);
- if (options.ip6_only) {
+ if (options.ip6_only) |ip6_only| {
if (posix.IPV6 == void) return error.OptionUnsupported;
- try setSocketOption(k, socket_fd, posix.IPPROTO.IPV6, posix.IPV6.V6ONLY, 1);
+ try setSocketOption(k, socket_fd, posix.IPPROTO.IPV6, posix.IPV6.V6ONLY, @intFromBool(ip6_only));
}
return socket_fd;
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
@@ -12407,9 +12407,9 @@ fn openSocketPosix(
};
errdefer closeFd(socket_fd);
- if (options.ip6_only) {
+ if (options.ip6_only) |ip6_only| {
if (posix.IPV6 == void) return error.OptionUnsupported;
- try setSocketOptionPosix(socket_fd, posix.IPPROTO.IPV6, posix.IPV6.V6ONLY, 1);
+ try setSocketOptionPosix(socket_fd, posix.IPPROTO.IPV6, posix.IPV6.V6ONLY, @intFromBool(ip6_only));
}
return socket_fd;
@@ -14496,7 +14496,7 @@ fn lookupDns(
var socket = s: {
if (any_ip6) ip6: {
const ip6_addr: IpAddress = .{ .ip6 = .unspecified(0) };
- const socket = ip6_addr.bind(t_io, .{ .ip6_only = true, .mode = .dgram }) catch |err| switch (err) {
+ const socket = ip6_addr.bind(t_io, .{ .ip6_only = false, .mode = .dgram }) catch |err| switch (err) {
error.AddressFamilyUnsupported => break :ip6,
else => |e| return e,
};
diff --git a/lib/std/Io/Uring.zig b/lib/std/Io/Uring.zig
@@ -5984,9 +5984,9 @@ fn socket(
};
errdefer ev.closeAsync(socket_fd);
- if (options.ip6_only) {
+ if (options.ip6_only) |ip6_only| {
if (linux.IPV6 == void) return error.OptionUnsupported;
- try ev.setsockopt(cancel_region, socket_fd, linux.IPPROTO.IPV6, linux.IPV6.V6ONLY, 1);
+ try ev.setsockopt(cancel_region, socket_fd, linux.IPPROTO.IPV6, linux.IPV6.V6ONLY, @intFromBool(ip6_only));
}
return socket_fd;
diff --git a/lib/std/Io/net.zig b/lib/std/Io/net.zig
@@ -281,7 +281,9 @@ pub const IpAddress = union(enum) {
/// The socket is restricted to sending and receiving IPv6 packets only.
/// In this case, an IPv4 and an IPv6 application can bind to a single port
/// at the same time.
- ip6_only: bool = false,
+ ///
+ /// The default is determined by system configuration.
+ ip6_only: ?bool = null,
/// Allow the socket to send datagrams to broadcast addresses.
/// When not enabled any attempt to send datagrams to a broadcast address
/// will fail with `error.AccessDenied`