Struct ipconfig::Adapter

source ·
pub struct Adapter { /* private fields */ }
Expand description

Represent an adapter.

Implementations§

source§

impl Adapter

source

pub fn adapter_name(&self) -> &str

Get the adapter’s name

source

pub fn ip_addresses(&self) -> &[IpAddr]

Get the adapter’s ip addresses (unicast ip addresses)

Examples found in repository?
examples/priority_list.rs (line 9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut adapters = ipconfig::get_adapters().unwrap();
    adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
    for adapter in adapters {
        println!(
            "{}: IfType: {:?}  IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
            adapter.friendly_name(),
            adapter.if_type(),
            adapter.ip_addresses(),
            adapter.ipv4_metric(),
            adapter.ipv6_metric()
        )
    }
}
source

pub fn prefixes(&self) -> &[(IpAddr, u32)]

Get the adapter’s prefixes. Returns a list of tuples (IpAddr, u32), where first element is a subnet address, e.g. 192.168.1.0 and second element is prefix length, e.g. 24

source

pub fn gateways(&self) -> &[IpAddr]

Get the adapter’s gateways

source

pub fn dns_servers(&self) -> &[IpAddr]

Get the adapter’s dns servers (the preferred dns server is first)

source

pub fn description(&self) -> &str

Get the adapter’s description

source

pub fn friendly_name(&self) -> &str

Get the adapter’s friendly name

Examples found in repository?
examples/priority_list.rs (line 7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut adapters = ipconfig::get_adapters().unwrap();
    adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
    for adapter in adapters {
        println!(
            "{}: IfType: {:?}  IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
            adapter.friendly_name(),
            adapter.if_type(),
            adapter.ip_addresses(),
            adapter.ipv4_metric(),
            adapter.ipv6_metric()
        )
    }
}
source

pub fn physical_address(&self) -> Option<&[u8]>

Get the adapter’s physical (MAC) address

Get the adapter Recieve Link Speed (bits per second)

Get the Trasnmit Link Speed (bits per second)

source

pub fn oper_status(&self) -> OperStatus

Check if the adapter is up (OperStatus is IfOperStatusUp)

source

pub fn if_type(&self) -> IfType

Get the interface type

Examples found in repository?
examples/priority_list.rs (line 8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut adapters = ipconfig::get_adapters().unwrap();
    adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
    for adapter in adapters {
        println!(
            "{}: IfType: {:?}  IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
            adapter.friendly_name(),
            adapter.if_type(),
            adapter.ip_addresses(),
            adapter.ipv4_metric(),
            adapter.ipv6_metric()
        )
    }
}
source

pub fn ipv6_if_index(&self) -> u32

Get the IPv6 interface index.

The return value can be used as an IPv6 scope id for link-local addresses.

source

pub fn ipv4_metric(&self) -> u32

Returns the metric used to compute route preference for IPv4

Examples found in repository?
examples/priority_list.rs (line 3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut adapters = ipconfig::get_adapters().unwrap();
    adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
    for adapter in adapters {
        println!(
            "{}: IfType: {:?}  IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
            adapter.friendly_name(),
            adapter.if_type(),
            adapter.ip_addresses(),
            adapter.ipv4_metric(),
            adapter.ipv6_metric()
        )
    }
}
source

pub fn ipv6_metric(&self) -> u32

Returns the metric used to compute route preference for IPv6

Examples found in repository?
examples/priority_list.rs (line 11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fn main() {
    let mut adapters = ipconfig::get_adapters().unwrap();
    adapters.sort_by(|ip1, ip2| ip1.ipv4_metric().cmp(&ip2.ipv4_metric()));
    for adapter in adapters {
        println!(
            "{}: IfType: {:?}  IPs: {:?} - IPv4 metric: {} IPv6 metric: {}",
            adapter.friendly_name(),
            adapter.if_type(),
            adapter.ip_addresses(),
            adapter.ipv4_metric(),
            adapter.ipv6_metric()
        )
    }
}

Trait Implementations§

source§

impl Debug for Adapter

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.