diff --git a/src/client.rs b/src/client.rs index 344321e..3d36490 100644 --- a/src/client.rs +++ b/src/client.rs @@ -17,7 +17,7 @@ use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable}; use network_interface::NetworkInterface; use network_interface::NetworkInterfaceConfig; -pub async fn client_mode(client_config: ClientConfiguration) { +pub async fn client_mode(client_config: ClientConfiguration, fd: i32) { info!("Starting client..."); let sock = UdpSocket::bind("0.0.0.0:25565").await.unwrap(); @@ -25,11 +25,7 @@ pub async fn client_mode(client_config: ClientConfiguration) { let mut config = tun2::Configuration::default(); info!("address: {:?}", &client_config.client.address); - config.address(&client_config.client.address) - .netmask("255.255.255.255") - .destination("0.0.0.0") - .tun_name("tun0") - .up(); + config.raw_fd(fd).up(); let dev = tun2::create(&config).unwrap(); let (mut dev_reader, mut dev_writer) = dev.split(); diff --git a/src/main.rs b/src/main.rs index c0576d7..64e5403 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,11 +26,17 @@ async fn main() { .value_name("B32_RAW") .help("Configuration file data (base32 encoded)") .takes_value(true)) + .arg(Arg::with_name("fd") + .long("fd") + .required(true) + .value_name("INT") + .help("File descriptor int") + .takes_value(true)) .get_matches(); let cfg_raw = matches.value_of("config").unwrap(); let config: ClientConfiguration = serde_yaml::from_slice(RFC4648.decode(cfg_raw.as_bytes()).unwrap().as_slice()).expect("Bad client config file structure"); - client::client_mode(config).await; + client::client_mode(config, matches.value_of("fd").unwrap().parse().unwrap()).await; } \ No newline at end of file