Skip to content

Commit a2c5169

Browse files
committed
fix
2 parents 39fa929 + 28f72fb commit a2c5169

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "netconfig-rs"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
rust-version = "1.85"
55
edition = "2021"
66
license = "MIT"

src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ impl From<widestring::error::Utf16Error> for Error {
4343
Self::UnexpectedMetadata
4444
}
4545
}
46+
47+
impl From<Error> for io::Error {
48+
fn from(value: Error) -> Self {
49+
match value {
50+
Error::Io(e) => e,
51+
e => io::Error::other(format!("{:?}", e)),
52+
}
53+
}
54+
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ impl Interface {
3030
pub fn mtu(&self) -> Result<u32, Error> {
3131
self.0.mtu()
3232
}
33+
#[cfg(windows)]
34+
pub fn mtu_v6(&self) -> Result<u32, Error> {
35+
self.0.mtu_v6()
36+
}
3337
pub fn set_mtu(&self, mtu: u32) -> Result<(), Error> {
3438
self.0.set_mtu(mtu)
3539
}

src/sys/linux/handle.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{Error, Interface};
44
use advmac::MacAddr6;
55
use ipnet::IpNet;
66
use libc::{AF_INET, AF_INET6, ARPHRD_ETHER};
7-
use log::debug;
87
use netlink_packet_route::{
98
address::Nla as AddressNla, AddressMessage, NetlinkHeader, NetlinkMessage, NetlinkPayload,
109
RtnlMessage, NLM_F_DUMP, NLM_F_REQUEST,
@@ -45,7 +44,6 @@ impl InterfaceHandle {
4544
let mut buf = vec![0; req.header.length as _];
4645
req.serialize(&mut buf);
4746

48-
debug!(">>> {:?}", req);
4947
socket.send(&buf, 0)?;
5048

5149
Ok(())
@@ -71,7 +69,6 @@ impl InterfaceHandle {
7169
let mut buf = vec![0; req.header.length as _];
7270
req.serialize(&mut buf);
7371

74-
debug!(">>> {:?}", req);
7572
socket.send(&buf, 0)?;
7673

7774
Ok(())

src/sys/win32/handle.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ fn convert_sockaddr(sa: SOCKADDR_INET) -> SocketAddr {
4343
}
4444

4545
impl InterfaceHandle {
46+
fn get_mtu(&self, family: ADDRESS_FAMILY) -> Result<u32, Error> {
47+
unsafe {
48+
let mut row: MIB_IPINTERFACE_ROW = std::mem::zeroed();
49+
InitializeIpInterfaceEntry(&mut row);
50+
row.Family = family;
51+
row.InterfaceIndex = self.index;
52+
let ret = GetIpInterfaceEntry(&mut row);
53+
ret.ok()?;
54+
Ok(row.NlMtu)
55+
}
56+
}
4657
fn mib_if_row2(&self) -> Result<MIB_IF_ROW2, Error> {
4758
let mut row = MIB_IF_ROW2 {
4859
InterfaceIndex: self.index,

src/sys/win32/mib_table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct MibTable<'a, T, R> {
1212
phantom: PhantomData<&'a R>,
1313
}
1414

15-
impl<'a, T, R> Default for MibTable<'a, T, R> {
15+
impl<T, R> Default for MibTable<'_, T, R> {
1616
fn default() -> Self {
1717
Self {
1818
table: std::ptr::null_mut(),
@@ -51,7 +51,7 @@ impl<'a> MibTable<'a, MIB_IPINTERFACE_TABLE, MIB_IPINTERFACE_ROW> {
5151
}
5252
}
5353

54-
impl<'a, T, R> Drop for MibTable<'a, T, R> {
54+
impl<T, R> Drop for MibTable<'_, T, R> {
5555
fn drop(&mut self) {
5656
if !self.table.is_null() {
5757
unsafe {

0 commit comments

Comments
 (0)