Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply rustfmt #137

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn disable_internal_nscd() {
if !sym_ptr.is_null() {
let __nss_disable_nscd = mem::transmute::<
*mut libc::c_void,
extern "C" fn(hell: unsafe extern "C" fn(size_t, *mut libc::c_void))
extern "C" fn(hell: unsafe extern "C" fn(size_t, *mut libc::c_void)),
>(sym_ptr);
__nss_disable_nscd(do_nothing);
}
Expand Down Expand Up @@ -131,21 +131,30 @@ impl Hostent {
#[derive(Debug)]
pub enum HostentError {
HError(i32),
Other(anyhow::Error)
Other(anyhow::Error),
}

fn from_libc_hostent(value: libc::hostent) -> Result<Hostent, HostentError> {
// validate value.h_addtype, and bail out if it's unsupported
if value.h_addrtype != libc::AF_INET && value.h_addrtype != libc::AF_INET6 {
return Err(HostentError::Other(anyhow!("unsupported address type: {}", value.h_addrtype)));
return Err(HostentError::Other(anyhow!(
"unsupported address type: {}",
value.h_addrtype
)));
}

// ensure value.h_length matches what we know from this address family
if value.h_addrtype == libc::AF_INET && value.h_length != 4 {
return Err(HostentError::Other(anyhow!("unsupported h_length for AF_INET: {}", value.h_length)));
return Err(HostentError::Other(anyhow!(
"unsupported h_length for AF_INET: {}",
value.h_length
)));
}
if value.h_addrtype == libc::AF_INET6 && value.h_length != 16 {
return Err(HostentError::Other(anyhow!("unsupported h_length for AF_INET6: {}", value.h_length)));
return Err(HostentError::Other(anyhow!(
"unsupported h_length for AF_INET6: {}",
value.h_length
)));
}

// construct the name field.
Expand Down Expand Up @@ -301,12 +310,10 @@ pub fn gethostbyname2_r(name: String, af: libc::c_int) -> Result<Hostent, Hosten
fn test_gethostbyname2_r() {
disable_internal_nscd();

let result =
gethostbyname2_r("localhost.".to_string(), libc::AF_INET);
let result = gethostbyname2_r("localhost.".to_string(), libc::AF_INET);
result.expect("Should resolve IPv4 localhost.");

let result =
gethostbyname2_r("localhost.".to_string(), libc::AF_INET6);
let result = gethostbyname2_r("localhost.".to_string(), libc::AF_INET6);
result.expect("Should resolve IPv6 localhost.");
}

Expand Down
Loading
Loading