Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334const std = @import("std");const linux = std.os.linux;const mem = std.mem;
header: linux.nlmsghdr,payload: []const u8,
const Self = @This();
pub const Iterator = struct { buf: []const u8,
pub const Error = error{ Truncated, Malformed, };
pub fn next(self: *Iterator) Error!?Self { if (self.buf.len == 0) return null; if (self.buf.len < @sizeOf(linux.nlmsghdr)) return Error.Truncated;
const header = mem.bytesToValue(linux.nlmsghdr, self.buf[0..@sizeOf(linux.nlmsghdr)]); if (header.len < @sizeOf(linux.nlmsghdr) or header.len > self.buf.len) return Error.Malformed;
const msg: Self = .{ .header = header, .payload = self.buf[@sizeOf(linux.nlmsghdr)..header.len], };
self.buf = self.buf[@min(mem.alignForward(usize, header.len, 4), self.buf.len)..]; return msg; }};