File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments