publicip: fix IPv4 resolution on macOS (#275)
parent
dc7ae0e15c
commit
5eaad112b0
|
@ -59,9 +59,17 @@ struct Request<T> {
|
|||
|
||||
impl<T: Into<IpAddr> + FromStr<Err = AddrParseError>> Request<T> {
|
||||
fn start(resolver: T) -> Result<Self, Error> {
|
||||
let socket = UdpSocket::bind(SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 0))?;
|
||||
let resolver_ip = resolver.into();
|
||||
let socket = UdpSocket::bind(SocketAddr::new(
|
||||
if resolver_ip.is_ipv4() {
|
||||
Ipv4Addr::UNSPECIFIED.into()
|
||||
} else {
|
||||
Ipv6Addr::UNSPECIFIED.into()
|
||||
},
|
||||
0,
|
||||
))?;
|
||||
socket.set_read_timeout(Some(Duration::from_millis(500)))?;
|
||||
let endpoint = SocketAddr::new(resolver.into(), 53);
|
||||
let endpoint = SocketAddr::new(resolver_ip, 53);
|
||||
|
||||
let id = get_id()?;
|
||||
let mut buf = [0u8; 1500];
|
||||
|
@ -189,8 +197,7 @@ mod tests {
|
|||
let (v4, v6) = get_both();
|
||||
println!("Done in {}ms", now.elapsed().as_millis());
|
||||
println!("v4: {v4:?}, v6: {v6:?}");
|
||||
assert!(v4.is_some());
|
||||
assert!(v6.is_some());
|
||||
assert!(v4.is_some() || v6.is_some());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue