| ... | @@ -14,7 +14,7 @@ pub const Address = extern union { | ... | @@ -14,7 +14,7 @@ pub const Address = extern union { |
| 14 | any: os.sockaddr, | 14 | any: os.sockaddr, |
| 15 | in: os.sockaddr_in, | 15 | in: os.sockaddr_in, |
| 16 | in6: os.sockaddr_in6, | 16 | in6: os.sockaddr_in6, |
| 17 | unix: os.sockaddr_un, | 17 | un: os.sockaddr_un, |
| 18 | | 18 | |
| 19 | // TODO this crashed the compiler | 19 | // TODO this crashed the compiler |
| 20 | //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0); | 20 | //pub const localhost = initIp4(parseIp4("127.0.0.1") catch unreachable, 0); |
| ... | @@ -40,6 +40,18 @@ pub const Address = extern union { | ... | @@ -40,6 +40,18 @@ pub const Address = extern union { |
| 40 | return error.InvalidIPAddressFormat; | 40 | return error.InvalidIPAddressFormat; |
| 41 | } | 41 | } |
| 42 | | 42 | |
| | 43 | pub fn parseUnix(path: []const u8) !Address { |
| | 44 | var sock_addr = os.sockaddr_un{ |
| | 45 | .family = os.AF_UNIX, |
| | 46 | .path = undefined, |
| | 47 | }; |
| | 48 | |
| | 49 | if (path.len > sock_addr.path.len) return error.NameTooLong; |
| | 50 | mem.copy(u8, &sock_addr.path, path); |
| | 51 | |
| | 52 | return Address{ .un = sock_addr }; |
| | 53 | } |
| | 54 | |
| 43 | pub fn parseExpectingFamily(name: []const u8, family: os.sa_family_t, port: u16) !Address { | 55 | pub fn parseExpectingFamily(name: []const u8, family: os.sa_family_t, port: u16) !Address { |
| 44 | switch (family) { | 56 | switch (family) { |
| 45 | os.AF_INET => return parseIp4(name, port), | 57 | os.AF_INET => return parseIp4(name, port), |
| ... | @@ -315,6 +327,9 @@ pub const Address = extern union { | ... | @@ -315,6 +327,9 @@ pub const Address = extern union { |
| 315 | } | 327 | } |
| 316 | try std.fmt.format(context, Errors, output, "]:{}", port); | 328 | try std.fmt.format(context, Errors, output, "]:{}", port); |
| 317 | }, | 329 | }, |
| | 330 | os.AF_UNIX => { |
| | 331 | try std.fmt.format(context, Errors, output, "{}", self.un.path); |
| | 332 | }, |
| 318 | else => unreachable, | 333 | else => unreachable, |
| 319 | } | 334 | } |
| 320 | } | 335 | } |