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

add feature to support DNS requests #579

Merged
merged 2 commits into from
May 22, 2024
Merged

add feature to support DNS requests #579

merged 2 commits into from
May 22, 2024

Conversation

stlankes
Copy link
Contributor

@stlankes stlankes commented May 20, 2024

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

@stlankes stlankes changed the title add feature to support DNS request add feature to support DNS requests May 20, 2024
@stlankes stlankes requested a review from mkroening May 20, 2024 14:48
@stlankes stlankes force-pushed the dns branch 2 times, most recently from 3529bb7 to 0864311 Compare May 20, 2024 15:22
stlankes added 2 commits May 21, 2024 16:44
In addition, the system call getaddrbyname is introduced.
It expect an array of u8 with a size of in_addr or of in6_addr.
The result of the DNS request is stored in the arry.

Example code to determine the address by name:

```
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);
```
@stlankes stlankes added this pull request to the merge queue May 22, 2024
Merged via the queue into hermit-os:main with commit d603b6f May 22, 2024
12 checks passed
@stlankes stlankes deleted the dns branch May 22, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants