1 use api::debian_service_client::DebianServiceClient; 2 use api::IpAddr; 3 4 use clap::Parser; 5 pub mod api { 6 tonic::include_proto!("com.android.virtualization.terminal.proto"); 7 } 8 9 #[derive(Parser)] 10 /// Flags for running command 11 pub struct Args { 12 /// grpc port number 13 #[arg(long)] 14 #[arg(alias = "grpc_port")] 15 grpc_port: String, 16 } 17 18 #[tokio::main] main() -> Result<(), String>19async fn main() -> Result<(), String> { 20 let args = Args::parse(); 21 let gateway_ip_addr = netdev::get_default_gateway()?.ipv4[0]; 22 let ip_addr = netdev::get_default_interface()?.ipv4[0].addr(); 23 24 let server_addr = format!("http://{}:{}", gateway_ip_addr.to_string(), args.grpc_port); 25 26 println!("local ip addr: {}", ip_addr.to_string()); 27 println!("coonect to grpc server {}", server_addr); 28 29 let mut client = DebianServiceClient::connect(server_addr).await.map_err(|e| e.to_string())?; 30 31 let request = tonic::Request::new(IpAddr { addr: ip_addr.to_string() }); 32 33 let response = client.report_vm_ip_addr(request).await.map_err(|e| e.to_string())?; 34 println!("response from server: {:?}", response); 35 Ok(()) 36 } 37