Skip to content

Commit

Permalink
Merge pull request #2 from wasix-org/fix_dns_resolve_0
Browse files Browse the repository at this point in the history
Fix dns resolve 0
  • Loading branch information
john-sharratt authored Jul 11, 2023
2 parents 076b6ec + e34e7a4 commit ef19cdc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion library/std/src/sys/wasix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,19 @@ impl<'a> TryFrom<&'a str> for LookupHost {
type Error = io::Error;

fn try_from(v: &'a str) -> io::Result<LookupHost> {
TryFrom::try_from((v, 0u16))
macro_rules! try_opt {
($e:expr, $msg:expr) => {
match $e {
Some(r) => r,
None => return Err(io::const_io_error!(io::ErrorKind::InvalidInput, $msg)),
}
};
}

// split the string by ':' and convert the second part to u16
let (host, port_str) = try_opt!(v.rsplit_once(':'), "invalid socket address");
let port: u16 = try_opt!(port_str.parse().ok(), "invalid port value");
TryFrom::try_from((host, port))
}
}

Expand Down

0 comments on commit ef19cdc

Please sign in to comment.