From 864fd0043032051f066882ee7252a0fb60e04219 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 4 Feb 2026 18:09:33 -0800 Subject: [PATCH] add Ip6Address --- net.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net.zig b/net.zig index 1b49b90057ad78c8daea57c7587ff679fea0e85d..1dab0850dffb51a1d6fecba4fd26c8737a77bf5b 100644 --- a/net.zig +++ b/net.zig @@ -13,11 +13,16 @@ const sys = switch (os) { pub const Address = extern union { any: sys.struct_sockaddr, in: Ip4Address, + in6: Ip6Address, pub fn initIp4(addr: [4]u8, hport: u16) Address { return .{ .in = Ip4Address.init(addr, hport) }; } + pub fn initIp6(addr: [8]u16, hport: u16) Address { + return .{ .in6 = Ip6Address.init(addr, hport) }; + } + pub fn size(adr: Address) sys.socklen_t { return switch (adr.any.family) { .INET => @sizeOf(sys.struct_sockaddr_in), @@ -30,6 +35,7 @@ pub const Address = extern union { pub fn port(adr: Address) u16 { return std.mem.bigToNative(u16, switch (adr.any.family) { .INET => adr.in.sa.port, + .INET6 => adr.in6.sa.port, else => unreachable, }); } @@ -91,6 +97,21 @@ pub const Ip4Address = extern struct { } }; +pub const Ip6Address = extern struct { + sa: sys.struct_sockaddr_in6, + + pub fn init(addr: [8]u16, port: u16) Ip6Address { + return Ip6Address{ + .sa = .{ + .port = std.mem.nativeToBig(u16, port), + .addr = .{ .addr = @bitCast(addr) }, + .flowinfo = 0, + .scope_id = 0, + }, + }; + } +}; + pub const Socket = switch (os) { .linux => enum(c_uint) { _ }, else => @compileError("TODO"), -- 2.54.0