This commit is contained in:
Brandon Thomas
2022-06-29 04:45:07 -04:00
parent 1c923f1d21
commit a2a0c5cda7
2 changed files with 13 additions and 79 deletions
View File
+13 -79
View File
@@ -1,38 +1,34 @@
//! Send "Unreal LiveLink" network packets that were recorded from Xsens Animate
//! This should help bypass XSens ridiculous software.
use anyhow::Result as AnyhowResult;
use pcap_parser::*; use pcap_parser::*;
use pcap_parser::traits::PcapReaderIterator; use pcap_parser::traits::PcapReaderIterator;
use std::fs::File; use std::fs::File;
use std::time::Duration; use std::time::Duration;
use tokio::net::UdpSocket; use tokio::net::UdpSocket;
use anyhow::Result as AnyhowResult; const LOCAL_ADDR : &'static str = "0.0.0.0:8022";
const REMOTE_ADDR : &'static str = "192.168.50.31:9763";
#[tokio::main] #[tokio::main]
pub async fn main() -> AnyhowResult<()> { pub async fn main() -> AnyhowResult<()> {
old_format().await?; old_format().await?;
Ok(()) Ok(())
} }
pub async fn old_format() -> AnyhowResult<()> { pub async fn old_format() -> AnyhowResult<()> {
let path = "animation.pcap";
let file = File::open(path)?;
let path = "anim.pcap";
let path = "capture2.pcap";
let file = File::open(path).unwrap();
let mut num_blocks = 0; let mut num_blocks = 0;
let mut reader = LegacyPcapReader::new(65536, file).expect("LegacyPcapReader"); let mut reader = LegacyPcapReader::new(65536, file)?;
let sock = UdpSocket::bind("0.0.0.0:8022").await?; let sock = UdpSocket::bind(LOCAL_ADDR).await?;
let remote_addr = "192.168.50.31:9763";
sock.connect(remote_addr).await?;
sock.connect(REMOTE_ADDR).await?;
loop { loop {
let mut buf = [0; 1024];
match reader.next() { match reader.next() {
Ok((offset, block)) => { Ok((offset, block)) => {
//println!("got new block"); //println!("got new block");
@@ -45,18 +41,14 @@ pub async fn old_format() -> AnyhowResult<()> {
}, },
PcapBlockOwned::Legacy(block) => { PcapBlockOwned::Legacy(block) => {
// use linktype to parse b.data() // use linktype to parse b.data()
println!("Block: {:?}", block); //println!("Block: {:?}", block);
//let len = sock.recv(&mut buf).await?;
//println!("{:?} bytes received from {:?}", len, remote_addr);
let slice = &block.data[32..]; let slice = &block.data[32..];
let len = sock.send(slice).await?; let len = sock.send(slice).await?;
//println!("Sent: {}", len);
tokio::time::sleep(Duration::from_millis(10)).await; tokio::time::sleep(Duration::from_millis(5)).await;
println!("Sent: {}", len);
}, },
PcapBlockOwned::NG(_) => unreachable!(), PcapBlockOwned::NG(_) => unreachable!(),
} }
@@ -73,61 +65,3 @@ pub async fn old_format() -> AnyhowResult<()> {
Ok(()) Ok(())
} }
pub fn new_format() {
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);
}