Skip to content

Commit 448d203

Browse files
Remove scope_id when parsing IPv6 addresses (#225)
* remove scope_id when parsing IPv6 addresses fix mitmproxy/mitmproxy#7547 * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent c4d9cb5 commit 448d203

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/ipc/mod.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ impl TryFrom<&Address> for SocketAddr {
99
type Error = AddrParseError;
1010

1111
fn try_from(address: &Address) -> Result<Self, Self::Error> {
12-
let ip = IpAddr::from_str(&address.host)?;
12+
// The macOS network system extension may return IP addresses with scope string.
13+
let host = address.host.split('%').next().unwrap();
14+
let ip = IpAddr::from_str(host)?;
1315
Ok(SocketAddr::from((ip, address.port as u16)))
1416
}
1517
}
@@ -37,3 +39,30 @@ impl TryFrom<InterceptConf> for intercept_conf::InterceptConf {
3739
intercept_conf::InterceptConf::try_from(conf.actions)
3840
}
3941
}
42+
43+
#[cfg(test)]
44+
mod tests {
45+
use super::*;
46+
47+
#[test]
48+
fn test_socketaddr_from_address() {
49+
let a = Address {
50+
host: "fe80::f0ff:88ff:febc:3df5".to_string(),
51+
port: 8080,
52+
};
53+
assert!(SocketAddr::try_from(&a).is_ok());
54+
55+
let b = Address {
56+
host: "invalid".to_string(),
57+
port: 8080,
58+
};
59+
assert!(SocketAddr::try_from(&b).is_err());
60+
61+
let c = Address {
62+
host: "fe80::f0ff:88ff:febc:3df5%awdl0".to_string(),
63+
port: 8080,
64+
};
65+
assert!(SocketAddr::try_from(&c).is_ok());
66+
assert_eq!(SocketAddr::try_from(&a), SocketAddr::try_from(&c));
67+
}
68+
}

0 commit comments

Comments
 (0)