mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-08 23:57:42 +00:00
refine code
This commit is contained in:
parent
ce8ecbe44e
commit
d4410264e6
2 changed files with 12 additions and 18 deletions
|
@ -14,7 +14,6 @@ use smoltcp::time::Instant;
|
||||||
use smoltcp::wire::{IpCidr, IpProtocol, Ipv4Packet, Ipv6Packet, TcpPacket, UdpPacket};
|
use smoltcp::wire::{IpCidr, IpProtocol, Ipv4Packet, Ipv6Packet, TcpPacket, UdpPacket};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::convert::{From, TryFrom};
|
use std::convert::{From, TryFrom};
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::Shutdown::Both;
|
use std::net::Shutdown::Both;
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||||
|
@ -28,11 +27,14 @@ pub enum DestinationHost {
|
||||||
Hostname(String),
|
Hostname(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for DestinationHost {
|
impl std::fmt::Display for DestinationHost {
|
||||||
fn to_string(&self) -> String {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
DestinationHost::Address(addr) => addr.to_string(),
|
DestinationHost::Address(addr) => match addr {
|
||||||
Hostname(name) => name.clone(),
|
IpAddr::V4(_) => addr.fmt(f),
|
||||||
|
IpAddr::V6(_) => write!(f, "[{}]", addr),
|
||||||
|
},
|
||||||
|
Hostname(name) => name.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,16 +67,9 @@ impl From<SocketAddr> for Destination {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Destination {
|
impl std::fmt::Display for Destination {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let host_part = match self.host {
|
write!(f, "{}:{}", self.host, self.port)
|
||||||
DestinationHost::Address(addr) => match addr {
|
|
||||||
IpAddr::V4(_) => addr.to_string(),
|
|
||||||
IpAddr::V6(_) => format!("[{addr}]"),
|
|
||||||
},
|
|
||||||
Hostname(_) => self.host.to_string(),
|
|
||||||
};
|
|
||||||
write!(f, "{}:{}", host_part, self.port)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,8 +88,8 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Connection {
|
impl std::fmt::Display for Connection {
|
||||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(f, "{} -> {}", self.src, self.dst)
|
write!(f, "{} -> {}", self.src, self.dst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ mod tests {
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::string::ToString;
|
|
||||||
|
|
||||||
use fork::Fork;
|
use fork::Fork;
|
||||||
use nix::sys::signal;
|
use nix::sys::signal;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue