fix: convert MacAddr from vector to int

Still expose a vector / slice API with .fromSlice,
This commit is contained in:
2026-04-15 19:44:48 -04:00
committed by Tangled
parent 1f500b9b0a
commit 7077aae9ce
2 changed files with 15 additions and 4 deletions

View File

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

View File

@@ -53,8 +53,19 @@ pub const EthIpUdp = packed struct(u336) { // 42 bytes * 8 bits = 336
// --- Ethernet --- // --- Ethernet ---
eth_type: u16 = std.os.linux.ETH.P.IP, eth_type: u16 = std.os.linux.ETH.P.IP,
src_mac: @Vector(6, u8), src_mac: MacAddr,
dst_mac: @Vector(6, u8) = @splat(0xff), dst_mac: MacAddr = .fromSlice(@splat(0xff)),
pub const MacAddr = packed struct {
int: I,
pub const V = @Vector(6, u8);
pub const I = @Int(.unsigned, @bitSizeOf(V));
pub fn fromSlice(s: V) MacAddr {
return .{ .int = @bitCast(s) };
}
};
pub fn toBytes(self: @This()) [336 / 8]u8 { pub fn toBytes(self: @This()) [336 / 8]u8 {
var res: [336 / 8]u8 = undefined; var res: [336 / 8]u8 = undefined;