| ... | ... | @@ -49,6 +49,14 @@ pub const Address = extern union { |
| 49 | 49 | }; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | pub fn format(adr: Address, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { |
| 53 | switch (adr.any.family) { |
| 54 | .INET => try adr.in.format(fmt, options, writer), |
| 55 | .INET6 => try adr.in6.format(fmt, options, writer), |
| 56 | else => |a| try writer.print("{{any:{s}}}", .{@tagName(a)}), |
| 57 | } |
| 58 | } |
| 59 | |
| 52 | 60 | pub fn size(adr: Address) sys.socklen_t { |
| 53 | 61 | return switch (adr.any.family) { |
| 54 | 62 | .INET => @sizeOf(sys.struct_sockaddr_in), |
| ... | ... | @@ -123,6 +131,14 @@ pub const Ip4Address = extern struct { |
| 123 | 131 | }, |
| 124 | 132 | }; |
| 125 | 133 | } |
| 134 | |
| 135 | pub fn format(adr: Ip4Address, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { |
| 136 | _ = fmt; |
| 137 | _ = options; |
| 138 | const parts: [4]u8 = @bitCast(adr.sa.addr.addr); |
| 139 | const port = @byteSwap(adr.sa.port); |
| 140 | try writer.print("{d}.{d}.{d}.{d}:{d}", .{ parts[0], parts[1], parts[2], parts[3], port }); |
| 141 | } |
| 126 | 142 | }; |
| 127 | 143 | |
| 128 | 144 | pub const Ip6Address = extern struct { |
| ... | ... | @@ -140,6 +156,13 @@ pub const Ip6Address = extern struct { |
| 140 | 156 | }, |
| 141 | 157 | }; |
| 142 | 158 | } |
| 159 | |
| 160 | pub fn format(adr: Ip6Address, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void { |
| 161 | _ = adr; |
| 162 | _ = fmt; |
| 163 | _ = options; |
| 164 | try writer.writeAll("{Ip6Address}"); |
| 165 | } |
| 143 | 166 | }; |
| 144 | 167 | |
| 145 | 168 | pub const Socket = switch (os) { |