From 6749ead6cb555e8081d354d3315d5c8f2bca2f56 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 29 Jun 2022 03:19:20 -0400 Subject: [PATCH] send packets to unreal from xsens (wip) --- Cargo.toml | 13 +++++++++++ src/main.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c6da218 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "packet-send" +version = "0.0.1" +authors = [] +publish = false +edition = "2018" + +[[bin]] +name = "packet-send" +src = "src/main.rs" + +[dependencies] +pcap-parser = "0.14.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a3d946d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,62 @@ + +use pcap_parser::*; +use pcap_parser::traits::PcapReaderIterator; +use std::fs::File; + +pub fn main() { + println!("Test"); + + //let path = "anim.pcap"; + let path = "anim.pcapng"; + + let file = File::open(path).unwrap(); + let mut num_blocks = 0; + let capacity = 199999999; + let mut reader = PcapNGReader::new(capacity, file).expect("PcapNGReader"); + let mut if_linktypes = Vec::new(); + loop { + match reader.next() { + Ok((offset, block)) => { + println!("got new block"); + num_blocks += 1; + match block { + PcapBlockOwned::NG(Block::SectionHeader(ref _shb)) => { + // starting a new section, clear known interfaces + if_linktypes = Vec::new(); + }, + PcapBlockOwned::NG(Block::InterfaceDescription(ref idb)) => { + if_linktypes.push(idb.linktype); + }, + PcapBlockOwned::NG(Block::EnhancedPacket(ref epb)) => { + assert!((epb.if_id as usize) < if_linktypes.len()); + let linktype = if_linktypes[epb.if_id as usize]; + #[cfg(feature="data")] + let res = pcap_parser::data::get_packetdata(epb.data, linktype, epb.caplen as usize); + }, + PcapBlockOwned::NG(Block::SimplePacket(ref spb)) => { + assert!(if_linktypes.len() > 0); + let linktype = if_linktypes[0]; + let blen = (spb.block_len1 - 16) as usize; + #[cfg(feature="data")] + let res = pcap_parser::data::get_packetdata(spb.data, linktype, blen); + }, + PcapBlockOwned::NG(_) => { + // can be statistics (ISB), name resolution (NRB), etc. + eprintln!("unsupported block"); + }, + PcapBlockOwned::Legacy(_) + | PcapBlockOwned::LegacyHeader(_) => unreachable!(), + } + reader.consume(offset); + }, + Err(PcapError::Eof) => break, + Err(PcapError::Incomplete) => { + eprintln!("Could not read complete data block."); + eprintln!("Hint: the reader buffer size may be too small, or the input file nay be truncated."); + break; + }, + Err(e) => panic!("error while reading: {:?}", e), + } + } + println!("num_blocks: {}", num_blocks); +} \ No newline at end of file