Crates.io | get_adapters_addresses |
lib.rs | get_adapters_addresses |
version | 0.1.1 |
source | src |
created_at | 2023-07-24 12:38:19.891641 |
updated_at | 2023-07-27 13:44:16.177562 |
description | A wrapper around win32 GetAdaptersAddresses(). Enumerate network interfaces, and associated IP addresses. |
homepage | https://gitlab.com/cratesio/get_adapters_addresses |
repository | https://gitlab.com/cratesio/get_adapters_addresses |
max_upload_size | |
id | 924537 |
size | 37,795 |
This crate provides a rust interface to the win32 function GetAdaptersAddresses.
There is a windows crate. But the function GetAdaptersAddresses is not fun to use.
The struct AdaptersAddresses
allocates and owns the buffer that GetAdaptersAddresses() wrote to.
Iterating over this produces Adapter
's.
Adapters are queries for their various attributes, often iterable.
use get_adapters_addresses::*;
fn main() -> Result<()> {
let adapter_addresses =
AdaptersAddresses::try_new(Family::Unspec, *Flags::default().include_gateways())?;
for adapter in &adapter_addresses {
println!("============================================================");
println!("adapter name: {:?}", adapter.adapter_name());
println!("friendly name: {:?}", adapter.friendly_name());
println!("description: {:?}", adapter.description());
println!("interface_type {:?}", adapter.interface_type());
if let Some(physical_address) = adapter.physical_address() {
println!(
"physical_address: {} {{{:X}}}",
physical_address,
physical_address.as_u64()
);
}
println!("status: {:?}", adapter.operational_status());
for addr in adapter.unicast_addresses() {
println!("\tunicast: {:?}", addr);
}
for addr in adapter.multicast_addresses() {
println!("\tmulticast: {:?}", addr);
}
for addr in adapter.anycast_addresses() {
println!("\tanycast: {:?}", addr);
}
for addr in adapter.dns_addresses() {
println!("\tdns: {:?}", addr);
}
for addr in adapter.gateway_addresses() {
println!("\tgateway: {:?}", addr);
}
println!("\tdhcpv4: {:?}", adapter.dhcpv4_address());
println!("\tdhcpv6: {:?}", adapter.dhcpv6_address());
}
Ok(())
}