Commit ebfa6b5e authored by MLA98's avatar MLA98

Update mod.rs with getnetcfg trial

parent 3e9ae5af
......@@ -36,6 +36,13 @@ type Interface = Rc<RefCell<EthernetInterface<'static, 'static, 'static, Network
const MAX_DURATION: Duration = Duration { millis: ::std::u64::MAX };
const MIN_DURATION: Duration = Duration { millis: 0 };
pub fn getnetcfg(key: &str) -> Result<String> {
let mut value = String::new();
let mut file = File::open(&format!("/etc/net/eth0/{}", key))?;
file.read_to_string(&mut value)?;
Ok(value.trim().to_string())
}
pub struct Smolnetd {
network_file: Rc<RefCell<File>>,
time_file: File,
......@@ -69,16 +76,29 @@ impl Smolnetd {
time_file: File,
netcfg_file: File,
) -> Smolnetd {
let hardware_addr = EthernetAddress::from_str(getcfg("mac").unwrap().trim())
.expect("Can't parse the 'mac' cfg");
let local_ip =
IpAddress::from_str(getcfg("ip").unwrap().trim()).expect("Can't parse the 'ip' cfg.");
let hardware_addr;
match getnetcfg("mac") {
Ok(value) => hardware_addr = EthernetAddress::from_str(value.trim()).expect("Can't parse the 'mac' cfg"),
Err(e) => panic!("Can't parse the 'mac' cfg") ,
}
let local_ip;
match getnetcfg("ip") {
Ok(value) => local_ip = IpAddress::from_str(value.trim()).expect("Can't parse the 'ip' cfg."),
Err(e) => panic!("Can't parse the 'ip' cfg") ,
}
let default_gw;
match getnetcfg("ip_router") {
Ok(value) => default_gw = Ipv4Address::from_str(value.trim()).expect("Can't parse the 'ip_router' cfg."),
Err(e) => panic!("Can't parse the 'ip_router' cfg") ,
}
let protocol_addrs = vec![
IpCidr::new(local_ip, 24),
IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8),
];
let default_gw = Ipv4Address::from_str(getcfg("ip_router").unwrap().trim())
.expect("Can't parse the 'ip_router' cfg.");
let buffer_pool = Rc::new(RefCell::new(BufferPool::new(Self::MAX_PACKET_SIZE)));
let input_queue = Rc::new(RefCell::new(VecDeque::new()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment