diff --git a/src/tun2proxy.rs b/src/tun2proxy.rs index 9f8f287..5c8100b 100644 --- a/src/tun2proxy.rs +++ b/src/tun2proxy.rs @@ -30,10 +30,7 @@ pub enum DestinationHost { impl std::fmt::Display for DestinationHost { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - DestinationHost::Address(addr) => match addr { - IpAddr::V4(_) => addr.fmt(f), - IpAddr::V6(_) => write!(f, "[{}]", addr), - }, + DestinationHost::Address(addr) => addr.fmt(f), Hostname(name) => name.fmt(f), } } @@ -69,7 +66,11 @@ impl From for Destination { impl std::fmt::Display for Destination { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}:{}", self.host, self.port) + if let DestinationHost::Address(IpAddr::V6(addr)) = self.host { + write!(f, "[{}]:{}", addr, self.port) + } else { + write!(f, "{}:{}", self.host, self.port) + } } }