command line arguments

This commit is contained in:
Brandon Thomas
2022-07-12 01:53:25 -04:00
parent a20468797f
commit 89c40511f7
4 changed files with 114 additions and 19 deletions
Generated
+73 -9
View File
@@ -2,12 +2,32 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "anyhow"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@@ -38,6 +58,21 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fc239e0f6cb375d2402d48afb92f76f5404fd1df208a41930ec81eda078bea"
[[package]]
name = "clap"
version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
@@ -122,15 +157,6 @@ version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]]
name = "packet-send"
version = "0.0.1"
dependencies = [
"anyhow",
"pcap-parser",
"tokio",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
@@ -238,6 +264,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.98"
@@ -249,6 +281,15 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "tokio"
version = "1.19.2"
@@ -286,6 +327,18 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@@ -356,3 +409,14 @@ name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "xsens-packet-send"
version = "0.0.1"
dependencies = [
"anyhow",
"clap",
"log",
"pcap-parser",
"tokio",
]
+7 -5
View File
@@ -1,15 +1,17 @@
[package]
name = "packet-send"
name = "xsens-packet-send"
version = "0.0.1"
authors = []
authors = ["Brandon Thomas"]
publish = false
edition = "2018"
[[bin]]
name = "packet-send"
name = "xsens-packet-send"
src = "src/main.rs"
[dependencies]
anyhow = "1.0.58"
clap = "2.34.0"
log = "0.4.17"
pcap-parser = "0.14.0"
tokio = { version = "1", features = ["full"] }
anyhow = "1.0.58"
tokio = { version = "1", features = ["full"] }
+34 -5
View File
@@ -2,6 +2,8 @@
//! This should help bypass XSens ridiculous software.
use anyhow::Result as AnyhowResult;
use clap::{App, Arg};
use log::info;
use pcap_parser::*;
use pcap_parser::traits::PcapReaderIterator;
use std::fs::File;
@@ -9,25 +11,52 @@ use std::time::Duration;
use tokio::net::UdpSocket;
const LOCAL_ADDR : &'static str = "0.0.0.0:8022";
//const REMOTE_ADDR : &'static str = "192.168.50.31:9763";
const REMOTE_ADDR : &'static str = "127.0.0.1:9763";
const DEFAULT_ANIMATION_PACKET_FILE : &'static str = "three_dancers_animation.pcap";
#[tokio::main]
pub async fn main() -> AnyhowResult<()> {
let matches = App::new("xsens-packet-send")
.arg(Arg::with_name("file")
.short("f")
.long("file")
.value_name("FILE")
.help("Packet file to read")
.takes_value(true))
.arg(Arg::with_name("host")
.short("h")
.long("host")
.value_name("HOST")
.help("Host and port to send traffic to")
.takes_value(true))
.get_matches();
let animation_file = matches.value_of("file")
.unwrap_or(DEFAULT_ANIMATION_PACKET_FILE);
let hostname = matches.value_of("host")
.unwrap_or(REMOTE_ADDR);
info!("Connecting to Unreal animation host: {}", hostname);
let socket = UdpSocket::bind(LOCAL_ADDR).await?;
socket.connect(REMOTE_ADDR).await?;
socket.connect(hostname).await?;
loop {
play_legacy_pcap_file_format(&socket).await?;
play_legacy_pcap_file_format(animation_file, &socket).await?;
tokio::time::sleep(Duration::from_millis(500)).await;
}
Ok(())
}
pub async fn play_legacy_pcap_file_format(socket: &UdpSocket) -> AnyhowResult<()> {
let path = "animation.pcap";
let file = File::open(path)?;
pub async fn play_legacy_pcap_file_format(animation_file: &str, socket: &UdpSocket) -> AnyhowResult<()> {
info!("Reading config file: {}", animation_file);
let file = File::open(animation_file)?;
let mut num_blocks = 0;
let mut reader = LegacyPcapReader::new(65536, file)?;