Skip to content

Commit 9ad9db8

Browse files
inet: fix SIOCGIFHWADDR
Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
1 parent 8599330 commit 9ad9db8

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/aero_kernel/src/socket/inet.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,16 @@ impl INodeInterface for InetSocket {
229229
fn ioctl(&self, command: usize, arg: usize) -> fs::Result<usize> {
230230
match command {
231231
SIOCGIFHWADDR => {
232-
let hwaddr =
233-
unsafe { core::slice::from_raw_parts_mut(arg as *mut u8, MacAddr::ADDR_SIZE) };
232+
let ifreq = VirtAddr::new(arg as _)
233+
.read_mut::<IfReq>()
234+
.ok_or(FileSystemError::NotSupported)?;
235+
236+
let name = ifreq.name().ok_or(FileSystemError::InvalidPath)?;
237+
assert!(name == "eth0");
238+
239+
let hwaddr = unsafe {
240+
core::slice::from_raw_parts_mut(ifreq.sa_data.as_mut_ptr(), MacAddr::ADDR_SIZE)
241+
};
234242

235243
let mac_addr = net::default_device().mac();
236244
hwaddr.copy_from_slice(&mac_addr.0.as_slice());

src/aero_syscall/src/consts.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* along with Aero. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20-
use core::ffi::CStr;
21-
2220
use crate::OpenFlags;
2321

2422
// syscall number constants:
@@ -367,12 +365,8 @@ impl IfReq {
367365
/// Get the interface name, e.g. "en0". [`None`] is returned if UTF-8
368366
/// validation failed.
369367
pub fn name(&self) -> Option<&str> {
370-
match CStr::from_bytes_until_nul(&self.name) {
371-
Ok(s) => s.to_str(),
372-
// The name does not have a null terminator, that means
373-
// the whole buffer has the name.
374-
Err(_) => core::str::from_utf8(&self.name),
375-
}
376-
.ok()
368+
let null_index = self.name.iter().position(|&x| x == 0).unwrap_or_default();
369+
let name = &self.name[..null_index];
370+
core::str::from_utf8(name).ok()
377371
}
378372
}

0 commit comments

Comments
 (0)