NetworkConfigManager

Struct NetworkConfigManager 

Source
pub struct NetworkConfigManager;
Expand description

网络配置管理器

Implementations§

Source§

impl NetworkConfigManager

Source

fn parse_subnet_mask(mask: &str) -> Result<u8, NetworkConfigError>

解析点分十进制子网掩码并计算前缀长度

§参数
  • mask - 点分十进制格式的子网掩码字符串 (如 “255.255.255.0”)
§返回值
  • Ok(u8) - 成功时返回前缀长度 (0-32)
  • Err(NetworkConfigError) - 失败时返回错误
§示例
parse_subnet_mask("255.255.255.0") // 返回 Ok(24)
parse_subnet_mask("255.255.0.0")   // 返回 Ok(16)
parse_subnet_mask("255.255.255.128") // 返回 Ok(25)
parse_subnet_mask("255.255.255.3") // 返回 Err (无效掩码)
Source

pub fn init_default_interface() -> Result<(), NetworkConfigError>

初始化默认网络接口配置

Source

pub fn set_ip_address( interface_name: &str, ip: &str, prefix: u8, ) -> Result<(), NetworkConfigError>

设置网络接口IP地址

Source

pub fn set_default_gateway( interface_name: &str, gateway: &str, ) -> Result<(), NetworkConfigError>

设置默认网关

Source

pub fn get_interface_config( interface_name: &str, ) -> Result<String, NetworkConfigError>

获取网络接口配置信息

Source

pub fn set_interface_config( interface_name: &str, ip: &str, gateway: &str, mask: &str, ) -> Result<(), NetworkConfigError>

设置网络接口配置

Source

pub fn list_interfaces() -> String

列出所有网络接口

Auto Trait Implementations§

§

impl Freeze for NetworkConfigManager

§

impl RefUnwindSafe for NetworkConfigManager

§

impl Send for NetworkConfigManager

§

impl Sync for NetworkConfigManager

§

impl Unpin for NetworkConfigManager

§

impl UnwindSafe for NetworkConfigManager

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.