Skip to content

Commit 500e82b

Browse files
fix: encoding of IPv6 addresses in impl From<SocketAddr> for Socket (#179)
1 parent 525bc13 commit 500e82b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/port_forwarding.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::ffi::OsStr;
66

77
use std::borrow::Cow;
88
use std::fmt;
9-
use std::net::{self, SocketAddr};
9+
use std::net::{self, IpAddr, SocketAddr};
1010
use std::path::{Path, PathBuf};
1111

1212
/// Type of forwarding
@@ -53,8 +53,12 @@ pub enum Socket<'a> {
5353

5454
impl From<SocketAddr> for Socket<'static> {
5555
fn from(addr: SocketAddr) -> Self {
56+
let host = match addr.ip() {
57+
IpAddr::V4(v4) => v4.to_string(),
58+
IpAddr::V6(v6) => format!("[{v6}]"),
59+
};
5660
Socket::TcpSocket {
57-
host: addr.ip().to_string().into(),
61+
host: host.into(),
5862
port: addr.port(),
5963
}
6064
}

0 commit comments

Comments
 (0)