mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
feat(Io.net): add allow_broadcast to BindOptions
* and implement it in `Threaded`, `Uring` and `Kqueue`
This commit is contained in:
committed by
Andrew Kelley
parent
0d25302d43
commit
1f79a9e4e3
@@ -1029,6 +1029,7 @@ fn netBindIp(
|
||||
var storage: Io.Threaded.PosixAddress = undefined;
|
||||
var addr_len = Io.Threaded.addressToPosix(address, &storage);
|
||||
try posixBind(k, socket_fd, &storage.any, addr_len);
|
||||
if (options.allow_broadcast) try setSocketOption(k, socket_fd, posix.SOL.SOCKET, posix.SO.BROADCAST, 1);
|
||||
try posixGetSockName(k, socket_fd, &storage.any, &addr_len);
|
||||
return .{ .handle = socket_fd, .address = Io.Threaded.addressFromPosix(&storage) };
|
||||
}
|
||||
|
||||
@@ -12196,6 +12196,7 @@ fn netBindIpPosix(
|
||||
var storage: PosixAddress = undefined;
|
||||
var addr_len = addressToPosix(address, &storage);
|
||||
try posixBind(socket_fd, &storage.any, addr_len);
|
||||
if (options.allow_broadcast) try setSocketOptionPosix(socket_fd, std.posix.SOL.SOCKET, std.posix.SO.BROADCAST, 1);
|
||||
try posixGetSockName(socket_fd, &storage.any, &addr_len);
|
||||
return .{ .handle = socket_fd, .address = addressFromPosix(&storage) };
|
||||
}
|
||||
@@ -12212,6 +12213,7 @@ fn netBindIpWindows(
|
||||
const socket_handle = try openSocketAfd(family, options);
|
||||
errdefer windows.CloseHandle(socket_handle);
|
||||
const bound_address = try bindSocketIpAfd(socket_handle, address, .Active);
|
||||
if (options.allow_broadcast) try setSocketOptionAfd(socket_handle, ws2_32.SOL.SOCKET, ws2_32.SO.BROADCAST, true);
|
||||
return .{ .handle = socket_handle, .address = bound_address };
|
||||
}
|
||||
|
||||
|
||||
@@ -4991,6 +4991,7 @@ fn netBindIp(
|
||||
var storage: PosixAddress = undefined;
|
||||
var addr_len = addressToPosix(address, &storage);
|
||||
try ev.bind(&maybe_sync.cancel_region, socket_fd, &storage.any, addr_len);
|
||||
if (options.allow_broadcast) try ev.setsockopt(&maybe_sync.cancel_region, socket_fd, linux.SOL.SOCKET, linux.SO.BROADCAST, 1);
|
||||
try ev.getsockname(try maybe_sync.enterSync(ev), socket_fd, &storage.any, &addr_len);
|
||||
return .{ .handle = socket_fd, .address = addressFromPosix(&storage) };
|
||||
}
|
||||
|
||||
@@ -282,6 +282,10 @@ pub const IpAddress = union(enum) {
|
||||
/// In this case, an IPv4 and an IPv6 application can bind to a single port
|
||||
/// at the same time.
|
||||
ip6_only: bool = false,
|
||||
/// 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`
|
||||
allow_broadcast: bool = false,
|
||||
mode: Socket.Mode,
|
||||
protocol: ?Protocol = null,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user