Skip to content

Commit

Permalink
返回具体错误信息
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed May 21, 2024
1 parent 440a832 commit faa7844
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vnt/src/util/dns_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ fn address_choose0(addrs: Vec<SocketAddr>) -> anyhow::Result<SocketAddr> {
let v4: Vec<SocketAddr> = addrs.iter().filter(|v| v.is_ipv4()).copied().collect();
let v6: Vec<SocketAddr> = addrs.iter().filter(|v| v.is_ipv6()).copied().collect();
let check_addr = |addrs: &Vec<SocketAddr>| -> anyhow::Result<SocketAddr> {
let mut err = Vec::new();
if !addrs.is_empty() {
let udp = if addrs[0].is_ipv6() {
UdpSocket::bind("[::]:0")?
} else {
UdpSocket::bind("0.0.0.0:0")?
};
for addr in addrs {
if udp.connect(addr).is_ok() {
if let Err(e) = udp.connect(addr) {
err.push((*addr, e));
} else {
return Ok(*addr);
}
}
}
Err(anyhow::anyhow!("Unable to connect to address {:?}", addrs))
Err(anyhow::anyhow!("Unable to connect to address {:?}", err))
};
if v6.is_empty() {
return check_addr(&v4);
Expand Down

0 comments on commit faa7844

Please sign in to comment.