NetworkInterface

Struct NetworkInterface 

Source
pub struct NetworkInterface {
    name: String,
    mac_address: EthernetAddress,
    device: Arc<dyn NetDevice>,
    ip_addresses: SpinLock<Vec<IpCidr>>,
    ipv4_gateway: SpinLock<Option<Ipv4Address>>,
    interrupt_enabled: SpinLock<bool>,
    last_interrupt_time: SpinLock<Instant>,
}
Expand description

网络接口

Fields§

§name: String§mac_address: EthernetAddress§device: Arc<dyn NetDevice>§ip_addresses: SpinLock<Vec<IpCidr>>§ipv4_gateway: SpinLock<Option<Ipv4Address>>§interrupt_enabled: SpinLock<bool>§last_interrupt_time: SpinLock<Instant>

Implementations§

Source§

impl NetworkInterface

Source

pub fn new(name: String, device: Arc<dyn NetDevice>) -> Self

创建新的网络接口

Source

pub fn name(&self) -> &str

获取接口名称

Source

pub fn mac_address(&self) -> EthernetAddress

获取MAC地址

Source

pub fn device(&self) -> &Arc<dyn NetDevice>

获取底层网络设备

Source

pub fn add_ip_address(&self, ip_cidr: IpCidr)

设置IP地址

Source

pub fn ip_addresses(&self) -> Vec<IpCidr>

获取所有IP地址

Source

pub fn set_ipv4_gateway(&self, gateway: Option<Ipv4Address>)

设置IPv4网关

Source

pub fn ipv4_gateway(&self) -> Option<Ipv4Address>

获取IPv4网关

Source

pub fn enable_interrupt(&self)

启用中断

Source

pub fn disable_interrupt(&self)

禁用中断

Source

pub fn is_interrupt_enabled(&self) -> bool

检查中断是否启用

Source

pub fn update_interrupt_time(&self)

更新最后中断时间

Source

pub fn create_smoltcp_interface(&self) -> SmoltcpInterface

创建smoltcp以太网接口

返回一个 SmoltcpInterface 包装器,它拥有 NetDeviceAdapter 和 Interface, 确保两者有相同的生命周期,避免悬垂指针问题。

Trait Implementations§

Source§

impl Driver for NetworkInterface

实现Driver trait

Source§

fn try_handle_interrupt(&self, irq: Option<usize>) -> bool

Source§

fn device_type(&self) -> DeviceType

Source§

fn get_id(&self) -> String

Source§

fn as_net(&self) -> Option<&dyn NetDevice>

将驱动程序转换为网络驱动程序(如果适用)
Source§

fn as_net_arc(self: Arc<Self>) -> Option<Arc<dyn NetDevice>>

将驱动程序转换为网络驱动程序 Arc(如果适用)
Source§

fn as_block(&self) -> Option<&dyn BlockDriver>

将驱动程序转换为块设备驱动程序(如果适用)
Source§

fn as_rtc(&self) -> Option<&dyn RtcDriver>

将驱动程序转换为实时时钟驱动程序(如果适用)
Source§

fn as_block_arc(self: Arc<Self>) -> Option<Arc<dyn BlockDriver>>

将驱动程序转换为块设备驱动程序 Arc(如果适用)
Source§

fn as_rtc_arc(self: Arc<Self>) -> Option<Arc<dyn RtcDriver>>

将驱动程序转换为实时时钟驱动程序 Arc(如果适用)
Source§

fn as_serial(&self) -> Option<&dyn SerialDriver>

将驱动程序转换为串口驱动程序(如果适用)

Auto Trait Implementations§

§

impl !Freeze for NetworkInterface

§

impl !RefUnwindSafe for NetworkInterface

§

impl Send for NetworkInterface

§

impl Sync for NetworkInterface

§

impl Unpin for NetworkInterface

§

impl !UnwindSafe for NetworkInterface

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.