nix icon indicating copy to clipboard operation
nix copied to clipboard

SockProtocol: Missing IPPROTO_IP

Open jornfranke opened this issue 2 years ago • 1 comments
trafficstars

Hi,

I try to implement a raw socket to be able to fetch all (sent/received) IP packets through a given network interface. For this I would like to use libc::IPPROTO_IP, but it does not seem to be available in SockProtocol.

I try to do the following (obviously nix::sys::socket::SockProtocol::IpProtoIp does not exist)

  let fd = match nix::sys::socket::socket(
            nix::sys::socket::AddressFamily::Packet,
            nix::sys::socket::SockType::Raw,
            nix::sys::socket::SockFlag::SOCK_NONBLOCK,
            nix::sys::socket::SockProtocol::IpProtoIp,
        ) {
            Err(err) => return Err(format!("Error: {}", err).to_string()),
            Ok(fd) => fd,
        };

        // attach to device
        match nix::sys::socket::setsockopt(
            fd,
            nix::sys::socket::sockopt::BindToDevice,
            &OsString::from(&iface.to_string()),
        ) {
            Ok(()) => (),
            Err(err) => return Err(format!("Error: {}", err).to_string()),
        };

Is there a workaround to add a protocol not supported by nix::sys::socket::SockProtocol?

Thanks.

jornfranke avatar Dec 29 '22 00:12 jornfranke

How hard does the core team think this would be? I'm interested in picking up some work on the project.

evanrittenhouse avatar Nov 12 '23 02:11 evanrittenhouse