| ... | @@ -153,8 +153,9 @@ pub const IpAddress = union(enum) { | ... | @@ -153,8 +153,9 @@ pub const IpAddress = union(enum) { |
| 153 | | 153 | |
| 154 | /// `port` is native-endian. | 154 | /// `port` is native-endian. |
| 155 | pub fn setPort(a: *IpAddress, port: u16) void { | 155 | pub fn setPort(a: *IpAddress, port: u16) void { |
| 156 | switch (a) { | 156 | switch (a.*) { |
| 157 | inline .ip4, .ip6 => |*x| x.port = port, | 157 | .ip4 => a.ip4.port = port, |
| | 158 | .ip6 => a.ip6.port = port, |
| 158 | } | 159 | } |
| 159 | } | 160 | } |
| 160 | | 161 | |
| ... | @@ -1430,6 +1431,11 @@ test "parsing IPv6 addresses" { | ... | @@ -1430,6 +1431,11 @@ test "parsing IPv6 addresses" { |
| 1430 | try testIp6Parse("ff02::"); | 1431 | try testIp6Parse("ff02::"); |
| 1431 | try testIp6Parse("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); | 1432 | try testIp6Parse("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); |
| 1432 | } | 1433 | } |
| | 1434 | test "IpAddress.setPort works" { |
| | 1435 | var addr: IpAddress = .{ .ip4 = undefined }; |
| | 1436 | addr.setPort(0); |
| | 1437 | try std.testing.expectEqual(0, addr.getPort()); |
| | 1438 | } |
| 1433 | | 1439 | |
| 1434 | fn testIp6Parse(input: []const u8) !void { | 1440 | fn testIp6Parse(input: []const u8) !void { |
| 1435 | return testIp6ParseTransform(input, input); | 1441 | return testIp6ParseTransform(input, input); |