commit 37109fa4ef5beea9c4ec1ea78e4fcc02df34be3c (tree)
parent 251f54d1d7d0f871f551c54d77f1a8238a041983
Author: Karel Marek <karel.marek@kernun.cz>
Date: Thu, 12 Feb 2026 10:16:42 +0100
Fix IpAddress.setPort
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/std/Io/net.zig b/lib/std/Io/net.zig
@@ -153,8 +153,9 @@ pub const IpAddress = union(enum) {
/// `port` is native-endian.
pub fn setPort(a: *IpAddress, port: u16) void {
- switch (a) {
- inline .ip4, .ip6 => |*x| x.port = port,
+ switch (a.*) {
+ .ip4 => a.ip4.port = port,
+ .ip6 => a.ip6.port = port,
}
}
@@ -1430,6 +1431,11 @@ test "parsing IPv6 addresses" {
try testIp6Parse("ff02::");
try testIp6Parse("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
}
+test "IpAddress.setPort works" {
+ var addr: IpAddress = .{ .ip4 = undefined };
+ addr.setPort(0);
+ try std.testing.expectEqual(0, addr.getPort());
+}
fn testIp6Parse(input: []const u8) !void {
return testIp6ParseTransform(input, input);