FAQ
Common questions about rawether: how it compares with pnet and pcap, running without root, Windows, async, packet parsing, VLANs, PTP, dropped frames and reporting a vulnerability.
Short answers, linking to the rest of the documentation. For anything security-relevant, the threat model is the reference.
What is rawether for?
Sending and receiving whole Ethernet frames from Rust, for protocols that run directly on layer 2: PTP, LLDP, TSN streams, PRP/HSR, PROFINET, EtherCAT, IEC 61850 GOOSE and Sampled Values, or your own test traffic. It gives you the frames; parsing them is up to you or another crate.
How does it compare with pnet or the pcap crate?
The pcap crate binds libpcap, a C library you need installed, and adds capture files and Windows (Npcap). pnet offers a portable data-link layer, including Windows, plus packet parsing. rawether has neither parsing nor Windows support. It is a small, safe wrapper over the kernel interfaces themselves, with only libc as a dependency, and it exposes what timing-sensitive protocols need: a zero-copy TPACKET_V3 ring, labelled hardware timestamps, SO_TXTIME launch times, VLAN tag restoration and drop counters. Choose by what you need.
Do I need to run as root?
No. On Linux, grant CAP_NET_RAW to the binary with sudo setcap cap_net_raw+ep <binary>, and call drop_capabilities() once your sockets are open. On macOS, give your group access to /dev/bpf* (Wireshark’s ChmodBPF does this). See Getting started.
Why does open fail with PermissionDenied after every build?
File capabilities belong to the file. cargo build writes a new binary, which has none, so run setcap again after each build. A small script or a cargo runner setting can do it for you.
Why does joining a multicast group fail on macOS without root?
macOS lets only root add a multicast address to an interface (SIOCADDMULTI), even when /dev/bpf* is open to you, so open fails with PermissionDenied. Run as root, or receive the group with promiscuous(true) and an EtherType filter.
Does it support Windows?
No. Windows has no raw layer-2 socket in the base system; it needs a driver such as Npcap. rawether builds on Windows, and Socket::open returns ErrorKind::Unsupported.
Does it work with tokio or async?
Yes, without an async dependency in rawether. A socket implements AsFd and AsRawFd and can be non-blocking, so tokio’s AsyncFd, mio or poll can drive it. See Event loops and async.
Why do I see VLAN tags that tcpdump on Linux does not show?
Many Linux NICs strip the 802.1Q tag into metadata. rawether puts it back by default, so data() is the frame as it was on the wire, and vlan_restored() tells you. Turn it off with Config::restore_vlan(false).
Why does drop_capabilities fail in my program?
Because another thread exists, and Linux capabilities are per thread: that thread would keep CAP_NET_RAW. Open the sockets and call drop_capabilities() before spawning threads or building a multi-threaded async runtime. See Event loops and async.
I am losing frames. What can I do?
Check stats().dropped first. If it grows, the ring is overflowing: give it more blocks (RxMode::Ring(RingConfig { block_count: 256, .. })), read on a dedicated thread, or filter more tightly in the kernel. If it stays at zero, the loss is before the socket: look at ethtool -S and /proc/net/softnet_stat.
Can I build a PTP implementation on it?
rawether provides the transport: PTP-over-Ethernet frames (EtherType 0x88F7) with hardware receive and transmit timestamps on Linux, each transmit timestamp matched to its frame by id, and the PTP hardware clock behind the interface. It is safe next to ptp4l: it reads the NIC’s timestamping configuration and never lowers it. The PTP protocol itself (messages, servo, clock adjustment) is yours or another crate’s.
Does rawether parse frames?
Only the Ethernet header, which is its own layer: p.frame() gives you the addresses, VLAN tags, EtherType (named for well-known protocols, such as EtherType::GOOSE) and payload, and FrameBuilder writes them. What follows the EtherType (PTP, LLDP, GOOSE, your protocol) is yours to parse, with your own code or a protocol crate. Treat it as untrusted input: check lengths before indexing.
Is the API stable?
No. rawether is pre-1.0, so minor versions may change the API. Changes are listed in the changelog.
How do I report a vulnerability?
Privately, through GitHub’s private vulnerability reporting. Include the OS and version, the rawether version, the configuration, and the smallest program and frames that show the problem.