netpkt/pcapng.rs#
Source: lib/netpkt/pcapng.rs
pcapng -- capture files in the pcapng format (IETF draft-ietf-opsawg-pcapng), as Wireshark
reads them
Writer::new(app) section header block (little endian, "app" as shb_userappl)
add_interface(name, link, snap) interface description block with nanosecond timestamps;
returns the interface id
packet(iface, t_ns, data) enhanced packet block (with an optional comment)
finish() -> Vec<u8> the file
read(bytes) -> Result<Capture> section header, interfaces and enhanced / simple packet
blocks of either byte order; other blocks are skipped
Timestamps are whatever the caller counts in nanoseconds (a simulator's virtual clock).
Link types: LINKTYPE_ETHERNET, LINKTYPE_C_HDLC (serial lines), LINKTYPE_RAW (bare IP).
LINKTYPE_ETHERNET: u16 = 1
/// bare IPv4 / IPv6 packets without a link header
LINKTYPE_RAW: u16 = 101
/// Cisco HDLC (address, control, an ethertype, the packet), as on serial lines
LINKTYPE_C_HDLC: u16 = 104
struct Writerwrites a pcapng file into memory
impl Writer
fn new(app: &str) -> Writera new file;appnames the program that wrote itfn add_interface(&mut self, name: &str, link: u16, snaplen: u32) -> u32an interface;linkis a LINKTYPE_* value,snaplen0 = unlimitedfn packet(&mut self, iface: u32, t_ns: u64, data: &[u8])a packet seen on interfaceifaceatt_nsnanosecondsfn packet_with_comment(&mut self, iface: u32, t_ns: u64, data: &[u8], comment: &str)fn interfaces(&self) -> u32fn bytes(&self) -> &[u8]fn finish(self) -> Vec<u8>struct Interfacean interface of a read capturelink: u16name: Stringunits: u64-- timestamp units per second
struct Packeta packet of a read captureiface: u32t_ns: u64-- nanoseconds (converted from the interface's resolution)data: Vec<u8>orig_len: u32comment: String
struct Capturea read captureapp: Stringinterfaces: Vec<Interface>packets: Vec<Packet>
enum ReadErrwhy a capture could not be readNotPcapngTruncatedBadBlock
fn read(bytes: &[u8]) -> Result<Capture, ReadErr>reads a pcapng file (one or more sections)