-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yngrtc
committed
Mar 2, 2024
1 parent
98775b5
commit ed0faab
Showing
3 changed files
with
28 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,37 +2,24 @@ use stun::client::*; | |
use stun::message::*; | ||
use stun::xoraddr::*; | ||
|
||
use clap::{App, Arg}; | ||
use clap::Parser; | ||
use shared::error::Error; | ||
use std::net::UdpSocket; | ||
|
||
fn main() -> Result<(), Error> { | ||
let mut app = App::new("STUN Client") | ||
.version("0.1.0") | ||
.author("Rain Liu <[email protected]>") | ||
.about("An example of STUN Client") | ||
.arg( | ||
Arg::with_name("FULLHELP") | ||
.help("Prints more detailed help information") | ||
.long("fullhelp"), | ||
) | ||
.arg( | ||
Arg::with_name("server") | ||
.required_unless("FULLHELP") | ||
.takes_value(true) | ||
.default_value("stun.l.google.com:19302") | ||
.long("server") | ||
.help("STUN Server"), | ||
); | ||
|
||
let matches = app.clone().get_matches(); | ||
#[derive(Parser)] | ||
#[command(name = "STUN Client")] | ||
#[command(author = "Rusty Rain <[email protected]>")] | ||
#[command(version = "0.1.0")] | ||
#[command(about = "An example of STUN Client", long_about = None)] | ||
struct Cli { | ||
#[arg(long, default_value_t = format!("stun.l.google.com:19302"))] | ||
server: String, | ||
} | ||
|
||
if matches.is_present("FULLHELP") { | ||
app.print_long_help().unwrap(); | ||
std::process::exit(0); | ||
} | ||
fn main() -> Result<(), Error> { | ||
let cli = Cli::parse(); | ||
|
||
let server = matches.value_of("server").unwrap(); | ||
let server = cli.server; | ||
|
||
let conn = UdpSocket::bind("0:0")?; | ||
println!("Local address: {}", conn.local_addr()?); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,22 @@ | ||
use clap::{App, Arg}; | ||
use clap::Parser; | ||
|
||
use stun::message::Message; | ||
|
||
fn main() { | ||
let mut app = App::new("STUN decode") | ||
.version("0.1.0") | ||
.author("Jtplouffe <[email protected]>") | ||
.about("An example of STUN decode") | ||
.arg( | ||
Arg::with_name("FULLHELP") | ||
.help("Prints more detailed help information") | ||
.long("fullhelp"), | ||
) | ||
.arg( | ||
Arg::with_name("data") | ||
.required_unless("FULLHELP") | ||
.takes_value(true) | ||
.index(1) | ||
.help("base64 encoded message, e.g. 'AAEAHCESpEJML0JTQWsyVXkwcmGALwAWaHR0cDovL2xvY2FsaG9zdDozMDAwLwAA'"), | ||
); | ||
|
||
let matches = app.clone().get_matches(); | ||
#[derive(Parser)] | ||
#[command(name = "STUN decode")] | ||
#[command(author = "Rusty Rain <[email protected]>")] | ||
#[command(version = "0.1.0")] | ||
#[command(about = "An example of STUN decode", long_about = None)] | ||
struct Cli { | ||
/// base64 encoded message, e.g. 'AAEAHCESpEJML0JTQWsyVXkwcmGALwAWaHR0cDovL2xvY2FsaG9zdDozMDAwLwAA'" | ||
#[arg(long)] | ||
data: String, | ||
} | ||
|
||
if matches.is_present("FULLHELP") { | ||
app.print_long_help().unwrap(); | ||
std::process::exit(0); | ||
} | ||
fn main() { | ||
let cli = Cli::parse(); | ||
|
||
let encoded_data = matches.value_of("data").unwrap(); | ||
let encoded_data = cli.data; | ||
let decoded_data = match base64::decode(encoded_data) { | ||
Ok(d) => d, | ||
Err(e) => panic!("Unable to decode base64 value: {e}"), | ||
|