Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from andir/fix-ipv6
Browse files Browse the repository at this point in the history
Handle IPv6-only results even in GETHOSTBYNAME
  • Loading branch information
flokli committed Nov 11, 2022
2 parents b03ba5f + 7ddd036 commit 59acf07
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,20 @@ pub fn handle_request(log: &Logger, request: &protocol::Request) -> Result<Vec<u
..AddrInfoHints::default()
};

let host = match getaddrinfo(Some(hostname), None, Some(hints)) {
Ok(addrs) => {
let addresses: std::io::Result<Vec<_>> = addrs
.filter(|x| match x {
Err(_) => false,
Ok(addr) => addr.sockaddr.is_ipv4(),
})
.map(|r| r.map(|a| a.sockaddr.ip()))
.collect();
let host = match getaddrinfo(Some(hostname), None, Some(hints))
.map(|addrs|
addrs.filter_map(|r| r.ok())
.filter(|r| r.sockaddr.is_ipv4())
.map(|a| a.sockaddr.ip())
.collect::<Vec<_>>())
{
// no matches found
Ok(addresses) if addresses.len() == 0 => {
Ok(None)
}
Ok(addresses) => {
Ok(Some(Host {
addresses: addresses?,
addresses,
hostname: hostname.to_string(),
}))
}
Expand Down

0 comments on commit 59acf07

Please sign in to comment.