Work on more Rust-side bindings
This commit is contained in:
parent
91a7fc6da1
commit
da5c6ed172
7 changed files with 116 additions and 2 deletions
30
networkmanager/src/config/ip4.rs
Normal file
30
networkmanager/src/config/ip4.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
use crate::interface::config::ip4::Ipv4ConfigProxy;
|
||||
use std::{net::Ipv4Addr, ops::Deref};
|
||||
use zbus::Result;
|
||||
|
||||
pub struct Ipv4Config<'a>(Ipv4ConfigProxy<'a>);
|
||||
|
||||
impl<'a> Ipv4Config<'a> {
|
||||
pub async fn addresses(&self) -> Result<Vec<Vec<Ipv4Addr>>> {
|
||||
let addresses = self.0.addresses().await?;
|
||||
Ok(addresses
|
||||
.into_iter()
|
||||
.map(|addresses| addresses.into_iter().map(Ipv4Addr::from).collect())
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for Ipv4Config<'a> {
|
||||
type Target = Ipv4ConfigProxy<'a>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Ipv4ConfigProxy<'a>> for Ipv4Config<'a> {
|
||||
fn from(config: Ipv4ConfigProxy<'a>) -> Self {
|
||||
Ipv4Config(config)
|
||||
}
|
||||
}
|
||||
35
networkmanager/src/config/ip6.rs
Normal file
35
networkmanager/src/config/ip6.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
use crate::interface::config::ip6::Ipv6ConfigProxy;
|
||||
use std::{net::Ipv6Addr, ops::Deref};
|
||||
use zbus::Result;
|
||||
|
||||
pub struct Ipv6Config<'a>(Ipv6ConfigProxy<'a>);
|
||||
|
||||
impl<'a> Ipv6Config<'a> {
|
||||
pub async fn addresses(&self) -> Result<Vec<Ipv6Addr>> {
|
||||
let addresses = self.0.addresses().await?;
|
||||
Ok(addresses
|
||||
.into_iter()
|
||||
.map(|(address, _, _)| {
|
||||
let address_bytes: [u8; 16] = address
|
||||
.try_into()
|
||||
.expect("NetworkManager gave invalid IPv6 addresss");
|
||||
Ipv6Addr::from(address_bytes)
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for Ipv6Config<'a> {
|
||||
type Target = Ipv6ConfigProxy<'a>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Ipv6ConfigProxy<'a>> for Ipv6Config<'a> {
|
||||
fn from(config: Ipv6ConfigProxy<'a>) -> Self {
|
||||
Ipv6Config(config)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue