Browse Source

Fix formatting

IPv6 addresses without ports are not enclosed in brackets. They only get
enclosed in brackets in combination with a port.
pull/19/head
B. Blechschmidt 3 years ago
parent
commit
e6e6c70006
  1. 11
      src/tun2proxy.rs

11
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<SocketAddr> 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)
}
}
}

Loading…
Cancel
Save