2021-12-09 01:28:29 +00:00
|
|
|
use prelude::*;
|
2021-12-05 03:39:53 +00:00
|
|
|
|
2021-12-09 01:28:29 +00:00
|
|
|
pub mod app_common;
|
|
|
|
mod client;
|
2021-12-08 22:45:39 +00:00
|
|
|
mod ip;
|
2021-12-09 01:28:29 +00:00
|
|
|
pub mod message;
|
|
|
|
mod prelude;
|
|
|
|
mod server;
|
2021-12-05 05:01:25 +00:00
|
|
|
mod tlv;
|
|
|
|
|
2021-12-05 03:39:53 +00:00
|
|
|
fn main () -> Result <(), AppError> {
|
2021-12-09 00:34:59 +00:00
|
|
|
let rt = tokio::runtime::Builder::new_current_thread ()
|
|
|
|
.enable_io ()
|
|
|
|
.enable_time ()
|
|
|
|
.build ()?;
|
2021-12-08 23:55:22 +00:00
|
|
|
|
|
|
|
rt.block_on (async_main ())?;
|
|
|
|
|
|
|
|
Ok (())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn async_main () -> Result <(), AppError> {
|
2021-11-26 21:46:27 +00:00
|
|
|
let mut args = env::args ();
|
|
|
|
|
|
|
|
let _exe_name = args.next ();
|
|
|
|
|
2021-12-05 03:46:56 +00:00
|
|
|
match get_mac_address() {
|
|
|
|
Ok(Some(ma)) => {
|
2021-12-05 20:15:01 +00:00
|
|
|
println!("Our MAC addr = {}", ma);
|
2021-12-05 03:46:56 +00:00
|
|
|
}
|
|
|
|
Ok(None) => println!("No MAC address found."),
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
}
|
|
|
|
|
2021-12-07 03:18:11 +00:00
|
|
|
let subcommand: Option <String> = args.next ();
|
|
|
|
|
|
|
|
match subcommand.as_ref ().map (|x| &x[..]) {
|
2021-12-05 19:58:18 +00:00
|
|
|
None => return Err (CliArgError::MissingSubcommand.into ()),
|
2021-12-09 01:28:29 +00:00
|
|
|
Some ("client") => client::client (args).await?,
|
2021-12-08 22:04:45 +00:00
|
|
|
Some ("my-ips") => my_ips ()?,
|
2021-12-09 01:28:29 +00:00
|
|
|
Some ("server") => server::server (args).await?,
|
2021-12-05 19:58:18 +00:00
|
|
|
Some (x) => return Err (CliArgError::UnknownSubcommand (x.to_string ()).into ()),
|
2021-11-26 21:46:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok (())
|
|
|
|
}
|
|
|
|
|
2021-12-08 22:04:45 +00:00
|
|
|
fn my_ips () -> Result <(), AppError> {
|
2021-12-09 02:06:01 +00:00
|
|
|
for addr in ip::get_ips ()?
|
2021-12-08 22:45:39 +00:00
|
|
|
{
|
|
|
|
println! ("{:?}", addr);
|
|
|
|
}
|
|
|
|
|
2021-12-08 22:04:45 +00:00
|
|
|
Ok (())
|
|
|
|
}
|