refactor: use packed struct for IpAddr

This is more intuitive than using u32 directly, and follows the same pattern as the new MAC addr handling
This commit is contained in:
2026-04-15 21:02:32 -04:00
committed by Tangled
parent 7077aae9ce
commit 91fdb2c6f8
2 changed files with 31 additions and 20 deletions

View File

@@ -46,11 +46,11 @@ pub fn sendRelay(self: *Client, io: Io, payload: []const u8, dest: [4]u8) !void
const rand = io_source.interface();
var headers: EthIpUdp = .{
.src_mac = .fromSlice(self.socket.mac),
.src_mac = .fromBytes(self.socket.mac),
.ip = .{
.id = rand.int(u16),
.src_addr = 0, //rand.int(u32),
.dst_addr = @bitCast([_]u8{ 255, 255, 255, 255 }),
.src_addr = .fromBytes(.{ 0, 0, 0, 0 }), //rand.int(u32),
.dst_addr = .fromBytes(.{ 255, 255, 255, 255 }),
.len = undefined,
},
.udp = .{
@@ -86,11 +86,11 @@ pub fn connect(self: Client, io: Io, payload: []const u8) (error{ BpfAttachFaile
const rand = io_source.interface();
var headers: EthIpUdp = .{
.src_mac = .fromSlice(self.socket.mac),
.src_mac = .fromBytes(self.socket.mac),
.ip = .{
.id = rand.int(u16),
.src_addr = 0, //rand.int(u32),
.dst_addr = @bitCast([_]u8{ 255, 255, 255, 255 }),
.src_addr = .fromBytes(.{ 0, 0, 0, 0 }), //rand.int(u32),
.dst_addr = .fromBytes(.{ 255, 255, 255, 255 }),
.len = undefined,
},
.udp = .{