| author | |
| committer | |
| log | 1f79a9e4e300affd111b51ec172bbeff42ca755a |
| tree | 7e38b88313dc690c728f7d19a9799025d5164334 |
| parent | 0d25302d43557d89b868b8925b2e98395d1ebe60 |
* and implement it in `Threaded`, `Uring` and `Kqueue`4 files changed, 8 insertions(+), 0 deletions(-)
lib/std/Io/Kqueue.zig+1| ... | @@ -1029,6 +1029,7 @@ fn netBindIp( | ... | @@ -1029,6 +1029,7 @@ fn netBindIp( |
| 1029 | var storage: Io.Threaded.PosixAddress = undefined; | 1029 | var storage: Io.Threaded.PosixAddress = undefined; |
| 1030 | var addr_len = Io.Threaded.addressToPosix(address, &storage); | 1030 | var addr_len = Io.Threaded.addressToPosix(address, &storage); |
| 1031 | try posixBind(k, socket_fd, &storage.any, addr_len); | 1031 | try posixBind(k, socket_fd, &storage.any, addr_len); |
| 1032 | if (options.allow_broadcast) try setSocketOption(k, socket_fd, posix.SOL.SOCKET, posix.SO.BROADCAST, 1); | ||
| 1032 | try posixGetSockName(k, socket_fd, &storage.any, &addr_len); | 1033 | try posixGetSockName(k, socket_fd, &storage.any, &addr_len); |
| 1033 | return .{ .handle = socket_fd, .address = Io.Threaded.addressFromPosix(&storage) }; | 1034 | return .{ .handle = socket_fd, .address = Io.Threaded.addressFromPosix(&storage) }; |
| 1034 | } | 1035 | } |
lib/std/Io/Threaded.zig+2| ... | @@ -12196,6 +12196,7 @@ fn netBindIpPosix( | ... | @@ -12196,6 +12196,7 @@ fn netBindIpPosix( |
| 12196 | var storage: PosixAddress = undefined; | 12196 | var storage: PosixAddress = undefined; |
| 12197 | var addr_len = addressToPosix(address, &storage); | 12197 | var addr_len = addressToPosix(address, &storage); |
| 12198 | try posixBind(socket_fd, &storage.any, addr_len); | 12198 | try posixBind(socket_fd, &storage.any, addr_len); |
| 12199 | if (options.allow_broadcast) try setSocketOptionPosix(socket_fd, std.posix.SOL.SOCKET, std.posix.SO.BROADCAST, 1); | ||
| 12199 | try posixGetSockName(socket_fd, &storage.any, &addr_len); | 12200 | try posixGetSockName(socket_fd, &storage.any, &addr_len); |
| 12200 | return .{ .handle = socket_fd, .address = addressFromPosix(&storage) }; | 12201 | return .{ .handle = socket_fd, .address = addressFromPosix(&storage) }; |
| 12201 | } | 12202 | } |
| ... | @@ -12212,6 +12213,7 @@ fn netBindIpWindows( | ... | @@ -12212,6 +12213,7 @@ fn netBindIpWindows( |
| 12212 | const socket_handle = try openSocketAfd(family, options); | 12213 | const socket_handle = try openSocketAfd(family, options); |
| 12213 | errdefer windows.CloseHandle(socket_handle); | 12214 | errdefer windows.CloseHandle(socket_handle); |
| 12214 | const bound_address = try bindSocketIpAfd(socket_handle, address, .Active); | 12215 | const bound_address = try bindSocketIpAfd(socket_handle, address, .Active); |
| 12216 | if (options.allow_broadcast) try setSocketOptionAfd(socket_handle, ws2_32.SOL.SOCKET, ws2_32.SO.BROADCAST, true); | ||
| 12215 | return .{ .handle = socket_handle, .address = bound_address }; | 12217 | return .{ .handle = socket_handle, .address = bound_address }; |
| 12216 | } | 12218 | } |
| 12217 | 12219 |
lib/std/Io/Uring.zig+1| ... | @@ -4991,6 +4991,7 @@ fn netBindIp( | ... | @@ -4991,6 +4991,7 @@ fn netBindIp( |
| 4991 | var storage: PosixAddress = undefined; | 4991 | var storage: PosixAddress = undefined; |
| 4992 | var addr_len = addressToPosix(address, &storage); | 4992 | var addr_len = addressToPosix(address, &storage); |
| 4993 | try ev.bind(&maybe_sync.cancel_region, socket_fd, &storage.any, addr_len); | 4993 | try ev.bind(&maybe_sync.cancel_region, socket_fd, &storage.any, addr_len); |
| 4994 | if (options.allow_broadcast) try ev.setsockopt(&maybe_sync.cancel_region, socket_fd, linux.SOL.SOCKET, linux.SO.BROADCAST, 1); | ||
| 4994 | try ev.getsockname(try maybe_sync.enterSync(ev), socket_fd, &storage.any, &addr_len); | 4995 | try ev.getsockname(try maybe_sync.enterSync(ev), socket_fd, &storage.any, &addr_len); |
| 4995 | return .{ .handle = socket_fd, .address = addressFromPosix(&storage) }; | 4996 | return .{ .handle = socket_fd, .address = addressFromPosix(&storage) }; |
| 4996 | } | 4997 | } |
lib/std/Io/net.zig+4| ... | @@ -282,6 +282,10 @@ pub const IpAddress = union(enum) { | ... | @@ -282,6 +282,10 @@ pub const IpAddress = union(enum) { |
| 282 | /// In this case, an IPv4 and an IPv6 application can bind to a single port | 282 | /// In this case, an IPv4 and an IPv6 application can bind to a single port |
| 283 | /// at the same time. | 283 | /// at the same time. |
| 284 | ip6_only: bool = false, | 284 | ip6_only: bool = false, |
| 285 | /// Allow the socket to send datagrams to broadcast addresses. | ||
| 286 | /// When not enabled any attempt to send datagrams to a broadcast address | ||
| 287 | /// will fail with `error.AccessDenied` | ||
| 288 | allow_broadcast: bool = false, | ||
| 285 | mode: Socket.Mode, | 289 | mode: Socket.Mode, |
| 286 | protocol: ?Protocol = null, | 290 | protocol: ?Protocol = null, |
| 287 | }; | 291 | }; |