in src/linux.rs [96:136]
fn new(remote: IpAddr, nlmsg_seq: u32) -> Self {
let addr = AddrBytes::new(remote);
#[expect(
clippy::cast_possible_truncation,
reason = "Structs lens are <= u8::MAX per `const_assert!`s above; `addr_bytes` is max. 16 for IPv6."
)]
let nlmsg_len =
(size_of::<nlmsghdr>() + size_of::<rtmsg>() + size_of::<rtattr>() + addr.len()) as u32;
Self {
nlmsg: nlmsghdr {
nlmsg_len,
nlmsg_type: RTM_GETROUTE,
nlmsg_flags: NLM_F_REQUEST | NLM_F_ACK,
nlmsg_seq,
..Default::default()
},
rtm: rtmsg {
rtm_family: match remote {
IpAddr::V4(_) => AF_INET,
IpAddr::V6(_) => AF_INET6,
},
rtm_dst_len: match remote {
IpAddr::V4(_) => 32,
IpAddr::V6(_) => 128,
},
rtm_table: RT_TABLE_MAIN,
rtm_scope: RT_SCOPE_UNIVERSE,
rtm_type: RTN_UNICAST,
..Default::default()
},
rt: rtattr {
#[expect(
clippy::cast_possible_truncation,
reason = "Structs len is <= u8::MAX per `const_assert!` above; `addr_bytes` is max. 16 for IPv6."
)]
rta_len: (size_of::<rtattr>() + addr.len()) as u16,
rta_type: RTA_DST,
},
addr: addr.into(),
}
}