The nix crate is a nice wrapper around libc for working with raw sockets, but it turns out that it only supports the TCP and UDP protocols over those raw sockets. I want to use, say, ICMP over raw sockets--as in, I want to use sendto with an ICMP packet and have it end up wrapped in an IP header + Ethernet header before heading out onto the network, just as it would with the standard libc functions. Are there any wrappers/crates out there that support this without me resorting to doing ugly FFI stuff myself? It would be great if there were a way to use getprotobyname or something similar with nix.
1
votes
1 Answers
0
votes
The Rust standard library currently has no raw socket capabilities. The lowest level networking library in existence is a direct FFI to libpcap. If you want to use any protocol besides TCP or UDP via the standard library, you'll have to implement it yourself or see if pnet has already done it.
Using pcap:
let mut handle = Device::lookup().unwrap().open().unwrap();
let data = &[0, 1, 2, 3, 5];
handle.sendpacket(data);
pnetcrate? - Sven Marnach