Try fetching the mac address directly from the network driver

This commit is contained in:
bjorn3
2024-01-07 15:38:15 +01:00
parent a992d901cf
commit 9d5c8207db
2 changed files with 13 additions and 3 deletions
+11
View File
@@ -12,11 +12,14 @@ use std::fs::File;
use std::os::unix::io::{FromRawFd, RawFd};
use std::process;
use std::rc::Rc;
use std::str::FromStr;
use event::EventQueue;
use netutils::getcfg;
use redox_netstack::error::{Error, Result};
use redox_netstack::logger;
use scheme::Smolnetd;
use smoltcp::wire::EthernetAddress;
mod buffer_pool;
mod link;
@@ -32,6 +35,13 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> {
.map_err(|e| Error::from_syscall_error(e, "failed to open network:"))?
as RawFd;
let hardware_addr = std::fs::read("network:mac")
.map(|mac_address| EthernetAddress::from_bytes(&mac_address))
.unwrap_or_else(|_| {
EthernetAddress::from_str(getcfg("mac").unwrap().trim())
.expect("Can't parse the 'mac' cfg")
});
trace!("opening :ip");
let ip_fd = syscall::open(":ip", O_RDWR | O_CREAT | O_NONBLOCK)
.map_err(|e| Error::from_syscall_error(e, "failed to open :ip"))? as RawFd;
@@ -75,6 +85,7 @@ fn run(daemon: redox_daemon::Daemon) -> Result<()> {
let smolnetd = Rc::new(RefCell::new(Smolnetd::new(
network_file,
hardware_addr,
ip_file,
udp_file,
tcp_file,
+2 -3
View File
@@ -10,7 +10,7 @@ use smoltcp::iface::{Config, Interface as SmoltcpInterface};
use smoltcp::phy::Tracer;
use smoltcp::time::{Duration, Instant};
use smoltcp::wire::{
EthernetAddress, HardwareAddress, IpAddress, IpCidr, IpListenEndpoint, Ipv4Address,
EthernetAddress, HardwareAddress, IpAddress, IpCidr, IpListenEndpoint, Ipv4Address,
};
use std::cell::RefCell;
use std::fs::File;
@@ -64,6 +64,7 @@ impl Smolnetd {
pub fn new(
network_file: File,
hardware_addr: EthernetAddress,
ip_file: File,
udp_file: File,
tcp_file: File,
@@ -71,8 +72,6 @@ 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 protocol_addrs = vec![
IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8),
];