hermit-os / hermit-rs

Hermit for Rust.
Apache License 2.0
1.66k stars 86 forks source link

add feature to support DNS requests #579

Closed stlankes closed 4 months ago

stlankes commented 4 months ago

The system call getaddrbyname is introduced and expects an array of u8 with the size of in_addr or in6_addr. The result of the DNS request is stored in the array.

Example:

use hermit_abi::in_addr;
let c_string = std::ffi::CString::new("rust-lang.org").expect("CString::new failed");
let name = c_string.into_raw();
let mut inaddr: in_addr = Default::default();
let _ = unsafe {
    hermit_abi::getaddrbyname(
        name,
        &mut inaddr as *mut _ as *mut u8,
        std::mem::size_of::<in_addr>(),
    )
};

// retake pointer to free memory
let _ = CString::from_raw(name);

This PR depends on hermit-os/kernel#1211