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