diff --git a/lib/std/Io/Kqueue.zig b/lib/std/Io/Kqueue.zig index 8d673525560c1898b7c1976979c0079feaebe676..63fd846b72abecaf75f44487d6023385b486d345 100644 --- 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 index 1b5db4d4dbdac8bb01b33b4a31b8356ad9970cd4..b23d0c1b23b52095af96cae95e186edcd377226a 100644 --- 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 index 0b800682a154af8c9b31acbf36a555920ea09431..9184cd574153b4768c76347d4e246120827b4a26 100644 --- 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 index 2115e73e4957c6cf91461918b0f3c4fcc7a2ccc2..c704d8b9e924da4578e447f9d3e5be3ad9f42533 100644 --- 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`