This commit is contained in:
Paul Sajna
2018-09-01 14:00:18 +00:00
committed by jD91mZM2
parent 3dbf9f872a
commit 07eb658a8a
23 changed files with 1616 additions and 52 deletions
+22
View File
@@ -0,0 +1,22 @@
use alloc::string::String;
use platform::rawfile::RawFile;
use platform::Line;
use platform::rlb::RawLineBuffer;
use c_str::CString;
pub fn get_dns_server() -> String {
let fd = match RawFile::open(&CString::new("/etc/resolv.conf").unwrap(), 0, 0) {
Ok(fd) => fd,
Err(_) => return String::new() // TODO: better error handling
};
let mut rlb = RawLineBuffer::new(*fd);
while let Line::Some(line) = rlb.next() {
if line.starts_with(b"nameserver ") {
return String::from_utf8(line[11..].to_vec()).unwrap_or_default();
}
}
// TODO: better error handling
String::new()
}