-
Notifications
You must be signed in to change notification settings - Fork 246
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request