From d65b9a4c687c415b71888469eb7d30e428fe3029 Mon Sep 17 00:00:00 2001 From: Sam Poder Date: Tue, 6 Jun 2023 15:05:42 +0000 Subject: [PATCH] Begin CLI Work Uses the Parser module + it sets up a help & version. --- Cargo.lock | 108 ++++++++++++++++++++++++++++++++++++++ burrow/Cargo.toml | 1 + burrow/src/main.rs | 10 ++++ tun/src/unix/linux/mod.rs | 2 +- 4 files changed, 120 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 4edb2ec..53cbe29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,55 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "anstyle-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + [[package]] name = "anyhow" version = "1.0.71" @@ -92,6 +141,7 @@ checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b" name = "burrow" version = "0.1.0" dependencies = [ + "clap", "tokio", "tun", ] @@ -173,6 +223,40 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "4.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "401a4694d2bf92537b6867d94de48c4842089645fdcdf6c71865b175d836e9c2" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72394f3339a76daf211e57d4bcb374410f3965dcc606dd0e03738c7888766980" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -566,6 +650,18 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" +[[package]] +name = "is-terminal" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys 0.48.0", +] + [[package]] name = "itoa" version = "1.0.6" @@ -1117,6 +1213,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.4.1" @@ -1365,6 +1467,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/burrow/Cargo.toml b/burrow/Cargo.toml index a984553..c47bc98 100644 --- a/burrow/Cargo.toml +++ b/burrow/Cargo.toml @@ -9,3 +9,4 @@ crate-type = ["lib", "staticlib"] [dependencies] tokio = { version = "1.21", features = ["rt", "macros"] } tun = { version = "0.1", path = "../tun" } +clap = "4.3.2" diff --git a/burrow/src/main.rs b/burrow/src/main.rs index 8dae842..091f9d7 100644 --- a/burrow/src/main.rs +++ b/burrow/src/main.rs @@ -1,6 +1,15 @@ +use clap::Parser; use tokio::io::Result; use tun::TunInterface; +#[derive(Parser)] +#[command(name = "Burrow")] +#[command(author = "Hack Club ")] +#[command(version = "0.1")] +#[command(about = "Burrow is a tool for burrowing through firewalls, built by teenagers at Hack Club.", long_about = None)] + +struct Cli {} + async fn try_main() -> Result<()> { let iface = TunInterface::new()?; println!("{:?}", iface.name()); @@ -10,5 +19,6 @@ async fn try_main() -> Result<()> { #[tokio::main(flavor = "current_thread")] async fn main() { + let cli = Cli::parse(); try_main().await.unwrap(); } diff --git a/tun/src/unix/linux/mod.rs b/tun/src/unix/linux/mod.rs index 8467731..07cf80b 100644 --- a/tun/src/unix/linux/mod.rs +++ b/tun/src/unix/linux/mod.rs @@ -4,7 +4,7 @@ use socket2::{Domain, SockAddr, Socket, Type}; use std::fs::OpenOptions; use std::io::{Error, Write}; use std::mem; -use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6}; +use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4}; use std::os::fd::RawFd; use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd};