mirror of
				https://github.com/dndx/phantun.git
				synced 2025-11-04 11:55:34 +08:00 
			
		
		
		
	feat(*) add DNS name support for --remote argument in both Client and
				
					
				
			Server
This commit is contained in:
		@@ -396,11 +396,10 @@ impl Stack {
 | 
			
		||||
 | 
			
		||||
                    } else {
 | 
			
		||||
                        trace!("Cache miss, checking the shared tuples table for connection");
 | 
			
		||||
                        let sender;
 | 
			
		||||
                        {
 | 
			
		||||
                        let sender = {
 | 
			
		||||
                            let tuples = shared.tuples.read().unwrap();
 | 
			
		||||
                            sender = tuples.get(&tuple).cloned();
 | 
			
		||||
                        }
 | 
			
		||||
                            tuples.get(&tuple).cloned()
 | 
			
		||||
                        };
 | 
			
		||||
 | 
			
		||||
                        if let Some(c) = sender {
 | 
			
		||||
                            trace!("Storing connection information into local tuples");
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ use fake_tcp::{Socket, Stack};
 | 
			
		||||
use log::{debug, error, info};
 | 
			
		||||
use std::collections::HashMap;
 | 
			
		||||
use std::convert::TryInto;
 | 
			
		||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
 | 
			
		||||
use std::net::{Ipv4Addr, SocketAddr};
 | 
			
		||||
use std::sync::Arc;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
use tokio::net::UdpSocket;
 | 
			
		||||
@@ -57,8 +57,8 @@ async fn main() {
 | 
			
		||||
                .short("r")
 | 
			
		||||
                .long("remote")
 | 
			
		||||
                .required(true)
 | 
			
		||||
                .value_name("IP:PORT")
 | 
			
		||||
                .help("Sets the address and port where Phantun Client connects to Phantun Server")
 | 
			
		||||
                .value_name("IP or HOST NAME:PORT")
 | 
			
		||||
                .help("Sets the address or host name and port where Phantun Client connects to Phantun Server")
 | 
			
		||||
                .takes_value(true),
 | 
			
		||||
        )
 | 
			
		||||
        .arg(
 | 
			
		||||
@@ -97,11 +97,18 @@ async fn main() {
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .parse()
 | 
			
		||||
        .expect("bad local address");
 | 
			
		||||
    let remote_addr: SocketAddrV4 = matches
 | 
			
		||||
        .value_of("remote")
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .parse()
 | 
			
		||||
        .expect("bad remote address");
 | 
			
		||||
 | 
			
		||||
    let remote_addr = tokio::net::lookup_host(matches.value_of("remote").unwrap())
 | 
			
		||||
        .await
 | 
			
		||||
        .expect("bad remote address or host")
 | 
			
		||||
        .next()
 | 
			
		||||
        .expect("unable to resolve remote host name");
 | 
			
		||||
    let remote_addr = if let SocketAddr::V4(addr) = remote_addr {
 | 
			
		||||
        addr
 | 
			
		||||
    } else {
 | 
			
		||||
        panic!("only IPv4 remote address is supported");
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let tun_local: Ipv4Addr = matches
 | 
			
		||||
        .value_of("tun_local")
 | 
			
		||||
        .unwrap()
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ use clap::{crate_version, App, Arg};
 | 
			
		||||
use fake_tcp::packet::MAX_PACKET_LEN;
 | 
			
		||||
use fake_tcp::Stack;
 | 
			
		||||
use log::{error, info};
 | 
			
		||||
use std::net::{Ipv4Addr, SocketAddr};
 | 
			
		||||
use std::net::Ipv4Addr;
 | 
			
		||||
use tokio::net::UdpSocket;
 | 
			
		||||
use tokio::time::{self, Duration};
 | 
			
		||||
use tokio_tun::TunBuilder;
 | 
			
		||||
@@ -31,8 +31,8 @@ async fn main() {
 | 
			
		||||
                .short("r")
 | 
			
		||||
                .long("remote")
 | 
			
		||||
                .required(true)
 | 
			
		||||
                .value_name("IP:PORT")
 | 
			
		||||
                .help("Sets the address and port where Phantun Server forwards UDP packets to, IPv6 address need to be specified as: \"[IPv6]:PORT\"")
 | 
			
		||||
                .value_name("IP or HOST NAME:PORT")
 | 
			
		||||
                .help("Sets the address or host name and port where Phantun Server forwards UDP packets to, IPv6 address need to be specified as: \"[IPv6]:PORT\"")
 | 
			
		||||
                .takes_value(true),
 | 
			
		||||
        )
 | 
			
		||||
        .arg(
 | 
			
		||||
@@ -71,11 +71,13 @@ async fn main() {
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .parse()
 | 
			
		||||
        .expect("bad local port");
 | 
			
		||||
    let remote_addr: SocketAddr = matches
 | 
			
		||||
        .value_of("remote")
 | 
			
		||||
        .unwrap()
 | 
			
		||||
        .parse()
 | 
			
		||||
        .expect("bad remote address");
 | 
			
		||||
 | 
			
		||||
    let remote_addr = tokio::net::lookup_host(matches.value_of("remote").unwrap())
 | 
			
		||||
        .await
 | 
			
		||||
        .expect("bad remote address or host")
 | 
			
		||||
        .next()
 | 
			
		||||
        .expect("unable to resolve remote host name");
 | 
			
		||||
 | 
			
		||||
    let tun_local: Ipv4Addr = matches
 | 
			
		||||
        .value_of("tun_local")
 | 
			
		||||
        .unwrap()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user