|
| 1 | +// Copyright (C) 2021-2023 The Aero Project Developers. |
| 2 | +// |
| 3 | +// This file is part of The Aero Project. |
| 4 | +// |
| 5 | +// Aero is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// Aero is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with Aero. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +//! IPv4 or `AF_RAW` sockets. |
| 19 | +
|
| 20 | +use alloc::sync::Arc; |
| 21 | + |
| 22 | +use aero_syscall::prelude::{IfReq, SIOCGIFINDEX}; |
| 23 | + |
| 24 | +use crate::arch::user_copy::UserRef; |
| 25 | + |
| 26 | +use crate::fs::inode::INodeInterface; |
| 27 | +use crate::fs::Result; |
| 28 | + |
| 29 | +use crate::mem::paging::VirtAddr; |
| 30 | + |
| 31 | +pub struct Ipv4Socket {} |
| 32 | + |
| 33 | +impl Ipv4Socket { |
| 34 | + pub fn new() -> Arc<Self> { |
| 35 | + Arc::new(Self {}) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +impl INodeInterface for Ipv4Socket { |
| 40 | + fn ioctl(&self, command: usize, arg: usize) -> Result<usize> { |
| 41 | + match command { |
| 42 | + SIOCGIFINDEX => { |
| 43 | + let mut ifreq = unsafe { UserRef::<IfReq>::new(VirtAddr::new(arg as _)) }; |
| 44 | + |
| 45 | + let name = ifreq.name().unwrap(); |
| 46 | + assert!(name == "eth0"); |
| 47 | + |
| 48 | + ifreq.data.ifindex = 1; // FIXME: Fill the actual interface index |
| 49 | + Ok(0) |
| 50 | + } |
| 51 | + |
| 52 | + _ => unimplemented!(), |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments