| ... | ... | @@ -10,14 +10,13 @@ test "" { |
| 10 | 10 | _ = @import("net/test.zig"); |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | const has_unix_sockets = @hasDecl(os, "sockaddr_un"); |
| 14 | |
| 13 | 15 | pub const Address = extern union { |
| 14 | 16 | any: os.sockaddr, |
| 15 | 17 | in: os.sockaddr_in, |
| 16 | 18 | in6: os.sockaddr_in6, |
| 17 | | un: switch (builtin.os) { |
| 18 | | .linux, .macosx, .freebsd, .netbsd => os.sockaddr_un, |
| 19 | | else => void, |
| 20 | | }, |
| 19 | un: if (has_unix_sockets) os.sockaddr_un else void, |
| 21 | 20 | |
| 22 | 21 | // TODO this crashed the compiler |
| 23 | 22 | //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0); |
| ... | ... | @@ -239,6 +238,7 @@ pub const Address = extern union { |
| 239 | 238 | } |
| 240 | 239 | |
| 241 | 240 | /// Returns the port in native endian. |
| 241 | /// Asserts that the address is ip4 or ip6. |
| 242 | 242 | pub fn getPort(self: Address) u16 { |
| 243 | 243 | const big_endian_port = switch (self.any.family) { |
| 244 | 244 | os.AF_INET => self.in.port, |
| ... | ... | @@ -249,6 +249,7 @@ pub const Address = extern union { |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /// `port` is native-endian. |
| 252 | /// Asserts that the address is ip4 or ip6. |
| 252 | 253 | pub fn setPort(self: *Address, port: u16) void { |
| 253 | 254 | const ptr = switch (self.any.family) { |
| 254 | 255 | os.AF_INET => &self.in.port, |