Fix IpAddress.setPort

This commit is contained in:
Karel Marek 2026-02-12 10:16:42 +01:00 committed by Andrew Kelley
parent 251f54d1d7
commit 37109fa4ef

View file

@ -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);