Skip to content

Commit 9d171f0

Browse files
socket::inet: implement SIOCGIFHWADDR
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 3870ef0 commit 9d171f0

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

patches/rust-libc/rust-libc.patch

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
From 06433417feda99e2f407026d95349e3dbde054d1 Mon Sep 17 00:00:00 2001
1+
From 1c11650435d49430ddc9838ae0e59a8bcdad8243 Mon Sep 17 00:00:00 2001
22
From: Andy-Python-Programmer <[email protected]>
3-
Date: Fri, 17 Feb 2023 18:18:23 +1100
3+
Date: Fri, 3 Mar 2023 16:39:55 +1100
44
Subject: [PATCH] <xxx>
55

66
---
77
.../linux_like/linux/gnu/b64/x86_64/mod.rs | 4 +-
88
src/unix/linux_like/linux/gnu/mod.rs | 4 +-
99
src/unix/linux_like/linux/mod.rs | 28 +-
10-
src/unix/mlibc/mod.rs | 457 ++++++++++++++++--
11-
4 files changed, 439 insertions(+), 54 deletions(-)
10+
src/unix/mlibc/mod.rs | 460 ++++++++++++++++--
11+
4 files changed, 442 insertions(+), 54 deletions(-)
1212

1313
diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs
1414
index e6307e2..cae81c4 100644
@@ -185,7 +185,7 @@ index be12190..c8762d5 100644
185185
.field("ifr_name", &self.ifr_name)
186186
.field("ifr_ifru", &self.ifr_ifru)
187187
diff --git a/src/unix/mlibc/mod.rs b/src/unix/mlibc/mod.rs
188-
index 2046530..abae13c 100644
188+
index 2046530..0d74760 100644
189189
--- a/src/unix/mlibc/mod.rs
190190
+++ b/src/unix/mlibc/mod.rs
191191
@@ -47,7 +47,6 @@ pub type fsfilcnt_t = ::c_uint;
@@ -734,7 +734,7 @@ index 2046530..abae13c 100644
734734
pub const F_GETOWN: ::c_int = 10;
735735
pub const F_SETOWN: ::c_int = 11;
736736
pub const O_ACCMODE: ::c_int = 7;
737-
@@ -644,23 +956,51 @@ pub const S_IXGRP: mode_t = 0o10;
737+
@@ -644,23 +956,54 @@ pub const S_IXGRP: mode_t = 0o10;
738738
pub const S_IXOTH: mode_t = 0o1;
739739
pub const S_IXUSR: mode_t = 0o100;
740740

@@ -784,10 +784,13 @@ index 2046530..abae13c 100644
784784
// options/ansi/include/limits.h
785785
pub const PTHREAD_STACK_MIN: ::size_t = 16384;
786786
+pub const PATH_MAX: ::size_t = 4096;
787+
+
788+
+// abis/linux/ioctls.h
789+
+pub const SIOCGIFHWADDR: ::c_ulong = 0x00008927;
787790

788791
// options/posix/include/pthread.h
789792
align_const! {
790-
@@ -668,9 +1008,12 @@ align_const! {
793+
@@ -668,9 +1011,12 @@ align_const! {
791794
__mlibc_state: 0,
792795
__mlibc_recursion: 0,
793796
__mlibc_flags: 0,
@@ -800,7 +803,7 @@ index 2046530..abae13c 100644
800803
};
801804
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
802805
__mlibc_m: 0,
803-
@@ -689,11 +1032,40 @@ pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0;
806+
@@ -689,11 +1035,40 @@ pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 0;
804807
pub const PTHREAD_PROCESS_SHARED: ::c_int = 1;
805808

806809
extern "C" {
@@ -841,7 +844,7 @@ index 2046530..abae13c 100644
841844
pub fn getgrgid_r(
842845
gid: ::gid_t,
843846
grp: *mut ::group,
844-
@@ -728,13 +1100,24 @@ extern "C" {
847+
@@ -728,13 +1103,24 @@ extern "C" {
845848
buflen: ::size_t,
846849
result: *mut *mut passwd,
847850
) -> ::c_int;
@@ -870,7 +873,7 @@ index 2046530..abae13c 100644
870873
pub fn pthread_create(
871874
thread: *mut ::pthread_t,
872875
attr: *const ::pthread_attr_t,
873-
@@ -752,6 +1135,8 @@ extern "C" {
876+
@@ -752,6 +1138,8 @@ extern "C" {
874877
addr: *mut ::sockaddr,
875878
addrlen: *mut ::socklen_t,
876879
) -> ::ssize_t;

src/aero_kernel/src/net/ethernet.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ use super::*;
2626

2727
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
2828
#[repr(C)]
29-
pub struct MacAddr(pub [u8; 6]);
29+
pub struct MacAddr(pub [u8; Self::ADDR_SIZE]);
3030

3131
impl MacAddr {
32-
pub const BROADCAST: Self = Self([0xff; 6]);
32+
pub const ADDR_SIZE: usize = 6;
33+
pub const BROADCAST: Self = Self([0xff; Self::ADDR_SIZE]);
3334
}
3435

3536
#[repr(u16)]

src/aero_kernel/src/socket/inet.rs

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

20+
use aero_syscall::prelude::SIOCGIFHWADDR;
2021
use aero_syscall::socket::MessageHeader;
2122
use aero_syscall::{IpProtocol, OpenFlags, SocketAddrInet, SocketType, SyscallError};
2223
use alloc::sync::{Arc, Weak};
@@ -29,7 +30,7 @@ use crate::fs::inode::{FileType, INodeInterface, Metadata, PollFlags};
2930
use crate::fs::{self, FileSystemError};
3031
use crate::net::ip::Ipv4Addr;
3132
use crate::net::udp::{self, Udp, UdpHandler};
32-
use crate::net::{Packet, PacketHeader, PacketTrait};
33+
use crate::net::{self, MacAddr, Packet, PacketHeader, PacketTrait};
3334
use crate::utils::sync::{BlockQueue, Mutex};
3435

3536
#[derive(Default)]
@@ -222,6 +223,21 @@ impl INodeInterface for InetSocket {
222223
.sum::<usize>())
223224
}
224225

226+
fn ioctl(&self, command: usize, arg: usize) -> fs::Result<usize> {
227+
match command {
228+
SIOCGIFHWADDR => {
229+
let hwaddr =
230+
unsafe { core::slice::from_raw_parts_mut(arg as *mut u8, MacAddr::ADDR_SIZE) };
231+
232+
let mac_addr = net::default_device().mac();
233+
hwaddr.copy_from_slice(&mac_addr.0.as_slice());
234+
Ok(0)
235+
}
236+
237+
_ => unreachable!("inet::ioctl(): unknown command {command}"),
238+
}
239+
}
240+
225241
fn poll(&self, table: Option<&mut fs::inode::PollTable>) -> fs::Result<PollFlags> {
226242
if let Some(table) = table {
227243
table.insert(&self.wq);

src/aero_syscall/src/consts.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,6 @@ pub struct FramebufferFScreenInfo {
346346
pub capabilities: u16,
347347
pub reserved: [u16; 2],
348348
}
349+
350+
// networking ioctls:
351+
pub const SIOCGIFHWADDR: usize = 0x8927;

0 commit comments

Comments
 (0)