Problem
I am currently working with raw sockets and need to set the IP_HDRINCL option to manually construct IP headers. Currently, rustix::net::sockopt does not appear to expose a wrapper for this option.
As a result, I have to fall back to unsafe code and libc to achieve this, which breaks the flow of using rustix for safe system calls.
Current Workaround
Currently, I have to implement it like this:
use rustix::fd::AsRawFd;
let one: i32 = 1;
unsafe {
libc::setsockopt(
fd.as_raw_fd(),
libc::IPPROTO_IP,
libc::IP_HDRINCL,
std::ptr::from_ref::<i32>(&one).cast(),
std::mem::size_of::<i32>() as u32,
);
}
Proposed Solution
It would be great to add set_ip_hdrincl (and potentially get_ip_hdrincl) to rustix::net::sockopt.
Desired API:
// In rustix::net::sockopt
pub fn set_ip_hdrincl<Fd: AsFd>(fd: &Fd, value: bool) -> rustix::io::Result<()> {
// ... implementation wrapping setsockopt with IPPROTO_IP / IP_HDRINCL
}
pub fn get_ip_hdrincl<Fd: AsFd>(fd: &Fd) -> rustix::io::Result<bool> {
// ... implementation wrapping getsockopt
}
Context
This is standard functionality for raw socket programming (e.g., when building custom network tools) and seems to fit well within the scope of rustix's networking primitives.
Problem
I am currently working with raw sockets and need to set the
IP_HDRINCLoption to manually construct IP headers. Currently,rustix::net::sockoptdoes not appear to expose a wrapper for this option.As a result, I have to fall back to
unsafecode andlibcto achieve this, which breaks the flow of usingrustixfor safe system calls.Current Workaround
Currently, I have to implement it like this:
Proposed Solution
It would be great to add
set_ip_hdrincl(and potentiallyget_ip_hdrincl) torustix::net::sockopt.Desired API:
Context
This is standard functionality for raw socket programming (e.g., when building custom network tools) and seems to fit well within the scope of
rustix's networking primitives.