Skip to content

Commit 9da331b

Browse files
committed
add description of sys_getaddrbyname
1 parent 02748ab commit 9da331b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/syscalls/socket.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,28 @@ pub unsafe extern "C" fn sys_getaddrbyname(
263263
-ENOSYS
264264
}
265265

266+
/// The system call `sys_getaddrbyname` determine the network host entry.
267+
/// It expects an array of u8 with a size of in_addr or of in6_addr.
268+
/// The result of the DNS request will be stored in this array.
269+
///
270+
/// # Example
271+
///
272+
/// ```
273+
/// use hermit_abi::in_addr;
274+
/// let c_string = std::ffi::CString::new("rust-lang.org").expect("CString::new failed");
275+
/// let name = c_string.into_raw();
276+
/// let mut inaddr: in_addr = Default::default();
277+
/// let _ = unsafe {
278+
/// hermit_abi::getaddrbyname(
279+
/// name,
280+
/// &mut inaddr as *mut _ as *mut u8,
281+
/// std::mem::size_of::<in_addr>(),
282+
/// )
283+
/// };
284+
///
285+
/// // retake pointer to free memory
286+
/// let _ = CString::from_raw(name);
287+
/// ```
266288
#[cfg(feature = "dns")]
267289
#[hermit_macro::system]
268290
#[no_mangle]

0 commit comments

Comments
 (0)