1 use crate::{ 2 c_str::CString, 3 fs::File, 4 header::fcntl, 5 io::{BufRead, BufReader}, 6 }; 7 use alloc::string::String; 8 9 pub fn get_dns_server() -> String { 10 let file = match File::open(&CString::new("/etc/resolv.conf").unwrap(), fcntl::O_RDONLY) { 11 Ok(file) => file, 12 Err(_) => return String::new(), // TODO: better error handling 13 }; 14 let file = BufReader::new(file); 15 16 for line in file.split(b'\n') { 17 let mut line = match line { 18 Ok(line) => line, 19 Err(_) => return String::new(), // TODO: pls handle errors 20 }; 21 if line.starts_with(b"nameserver ") { 22 line.drain(..11); 23 return String::from_utf8(line).unwrap_or_default(); 24 } 25 } 26 27 // TODO: better error handling 28 String::new() 29 } 30