use std::mem::size_of;
use crate::ffi::*;
pub unsafe trait Bytes {
fn tail(&self, max: usize) -> usize {
max
}
}
unsafe impl Bytes for () {}
unsafe impl Bytes for u8 {}
unsafe impl Bytes for u16 {}
unsafe impl Bytes for u32 {}
unsafe impl Bytes for nlmsgerr {}
unsafe impl Bytes for ndmsg {}
unsafe impl Bytes for rtmsg {}
unsafe impl Bytes for rtgenmsg {}
unsafe impl Bytes for ifaddrmsg {}
unsafe impl Bytes for ifinfomsg {}
unsafe impl Bytes for rtnl_link_stats {}
unsafe impl Bytes for rtnl_link_stats64 {}
unsafe impl Bytes for inet_diag_req_v2 {}
unsafe impl Bytes for inet_diag_msg {}
unsafe impl Bytes for tcp_info {}
unsafe impl Bytes for cn_proc_event {}
unsafe impl Bytes for nlmsghdr {
fn tail(&self, max: usize) -> usize {
let x = self.nlmsg_len as usize;
let y = size_of::<Self>();
x.checked_sub(y).unwrap_or(max)
}
}
unsafe impl Bytes for nlattr {
fn tail(&self, max: usize) -> usize {
let x = self.nla_len as usize;
let y = size_of::<Self>();
x.checked_sub(y).unwrap_or(max)
}
}
unsafe impl Bytes for rtattr {
fn tail(&self, max: usize) -> usize {
let x = self.rta_len as usize;
let y = size_of::<Self>();
x.checked_sub(y).unwrap_or(max)
}
}