Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade deps: windows-rs has breaking changes #23

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ readme = "README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitflags = "2.1.0"
futures = "0.3.28"
uuid = { version = "1.3", features = ["v4", "serde", "v6"] }
bitflags = "2.4.2"
futures = "0.3.30"
uuid = { version = "1.7", features = ["v4", "serde", "v6"] }
ipnetwork = "0.20.0"

[dependencies.windows]
version = "0.52.0"
version = "0.54.0"
features = [
"Win32_Foundation",
"Win32_Security",
Expand All @@ -33,10 +33,10 @@ features = [
]

[dev-dependencies]
clap = {version = "4.0.32", features = ["derive"]}
ctrlc = "3.2.4"
futures = "0.3.28"
tokio = { version = "1.28.2", features = ["full"] }
clap = {version = "4.5.2", features = ["derive"]}
ctrlc = "3.4.4"
futures = "0.3.30"
tokio = { version = "1.36.0", features = ["full"] }
smoltcp = "0.11.0"
prettytable-rs = "0.10.0"
crossterm = "0.27.0"
Expand Down
7 changes: 2 additions & 5 deletions examples/listadapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn main() -> Result<()> {
match driver.get_hw_packet_filter(adapter.get_handle()) {
Err(err) => println!(
"Getting OID_GEN_CURRENT_PACKET_FILTER Error: {}",
err.message().to_string_lossy()
err.message()
),
Ok(current_packet_filter) => {
println!("\t OID_GEN_CURRENT_PACKET_FILTER: 0x{current_packet_filter:08X}")
Expand All @@ -62,10 +62,7 @@ fn main() -> Result<()> {
MacAddress::default(),
);
if let Err(err) = driver.ndis_get_request::<_>(&mut current_address_request) {
println!(
"Getting OID_802_3_CURRENT_ADDRESS Error: {}",
err.message().to_string_lossy()
)
println!("Getting OID_802_3_CURRENT_ADDRESS Error: {}", err.message(),)
} else {
println!(
"\t OID_802_3_CURRENT_ADDRESS: {}",
Expand Down
17 changes: 11 additions & 6 deletions src/ndisapi/static_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl Ndisapi {
KEY_READ,
&mut target_key,
)
.ok()
};

if result.is_err() {
Expand Down Expand Up @@ -313,7 +314,8 @@ impl Ndisapi {
KEY_READ,
&mut hkey,
)
};
}
.ok();

let mut value_type = REG_VALUE_TYPE::default();
let mut data = vec![0u16; 256];
Expand All @@ -330,7 +332,8 @@ impl Ndisapi {
Some(data.as_mut_ptr() as *const u8 as *mut u8),
Some(&mut data_size),
)
};
}
.ok();

if result.is_ok() {
friendly_name = if let Ok(name) = String::from_utf16(&data[..data_size as usize]) {
Expand Down Expand Up @@ -373,7 +376,8 @@ impl Ndisapi {
KEY_WRITE,
&mut hkey,
)
};
}
.ok();

if result.is_ok() {
result = unsafe {
Expand All @@ -384,7 +388,8 @@ impl Ndisapi {
REG_DWORD,
Some(mtu_decrement.to_ne_bytes().as_ref()),
)
};
}
.ok();
}

result
Expand Down Expand Up @@ -471,7 +476,7 @@ impl Ndisapi {
};
}

result
result.ok()
}

/// Returns the current default filter mode value applied to each adapter when it appears in the system.
Expand Down Expand Up @@ -559,7 +564,7 @@ impl Ndisapi {
};
}

result
result.ok()
}

/// Retrieves the pool size multiplier for the Windows Packet Filter driver from the Windows registry.
Expand Down
2 changes: 1 addition & 1 deletion src/netlib/ip_helper/network_adapter_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl IphlpNetworkAdapterInfo {
};
}

result
result.ok()
}

/// Checks if IP address information in the provided network_adapter_info is different
Expand Down
16 changes: 8 additions & 8 deletions src/netlib/ip_helper/network_adapter_info/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl IphlpNetworkAdapterInfo {
address_row.DadState = IpDadStatePreferred;

// Call the CreateUnicastIpAddressEntry function (you need to implement this function)
match unsafe { CreateUnicastIpAddressEntry(&address_row) } {
match unsafe { CreateUnicastIpAddressEntry(&address_row).ok() } {
Ok(_) => Some(address_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -130,7 +130,7 @@ impl IphlpNetworkAdapterInfo {
address_row.OnLinkPrefixLength = prefix_length;
address_row.DadState = IpDadStatePreferred;

match unsafe { CreateUnicastIpAddressEntry(&address_row) } {
match unsafe { CreateUnicastIpAddressEntry(&address_row) }.ok() {
Ok(_) => Some(address_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -180,15 +180,15 @@ impl IphlpNetworkAdapterInfo {
pub fn reset_unicast_addresses(&self) -> bool {
let mut table: *mut MIB_UNICASTIPADDRESS_TABLE = std::ptr::null_mut();

match unsafe { GetUnicastIpAddressTable(AF_UNSPEC, &mut table) } {
match unsafe { GetUnicastIpAddressTable(AF_UNSPEC, &mut table) }.ok() {
Ok(_) => {
for i in 0..unsafe { (*table).NumEntries } {
let entry = unsafe { &mut (*table).Table[i as usize] };
if IfLuid::from(entry.InterfaceLuid) == self.luid {
let _ = unsafe { DeleteUnicastIpAddressEntry(entry) };
}
}
let _ = unsafe { FreeMibTable(table as *mut _) };
unsafe { FreeMibTable(table as *mut _) };
true
}
Err(_) => false,
Expand All @@ -213,7 +213,7 @@ impl IphlpNetworkAdapterInfo {
pub fn delete_unicast_address_ipv4(&self, address: Ipv4Addr) -> bool {
let mut table: *mut MIB_UNICASTIPADDRESS_TABLE = std::ptr::null_mut();

match unsafe { GetUnicastIpAddressTable(AF_INET, &mut table) } {
match unsafe { GetUnicastIpAddressTable(AF_INET, &mut table) }.ok() {
Ok(_) => {
for i in 0..unsafe { (*table).NumEntries } {
let entry = unsafe { &(*table).Table[i as usize] };
Expand All @@ -227,7 +227,7 @@ impl IphlpNetworkAdapterInfo {
}
}

let _ = unsafe { FreeMibTable(table as *mut _) };
unsafe { FreeMibTable(table as *mut _) };
true
}
Err(_) => false,
Expand All @@ -252,7 +252,7 @@ impl IphlpNetworkAdapterInfo {
pub fn delete_unicast_address_ipv6(&self, address: Ipv6Addr) -> bool {
let mut table: *mut MIB_UNICASTIPADDRESS_TABLE = std::ptr::null_mut();

match unsafe { GetUnicastIpAddressTable(AF_INET6, &mut table) } {
match unsafe { GetUnicastIpAddressTable(AF_INET6, &mut table) }.ok() {
Ok(_) => {
for i in 0..unsafe { (*table).NumEntries } {
let entry = unsafe { &(*table).Table[i as usize] };
Expand All @@ -264,7 +264,7 @@ impl IphlpNetworkAdapterInfo {
}
}

let _ = unsafe { FreeMibTable(table as *mut _) };
unsafe { FreeMibTable(table as *mut _) };
true
}
Err(_) => false,
Expand Down
8 changes: 4 additions & 4 deletions src/netlib/ip_helper/network_adapter_info/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl IphlpNetworkAdapterInfo {
forward_row.Protocol = MIB_IPPROTO_NT_STATIC;
forward_row.Origin = NlroManual;

match unsafe { CreateIpForwardEntry2(&forward_row) } {
match unsafe { CreateIpForwardEntry2(&forward_row) }.ok() {
Ok(_) => Some(forward_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl IphlpNetworkAdapterInfo {
forward_row.Protocol = MIB_IPPROTO_NT_STATIC;
forward_row.Origin = NlroManual;

match unsafe { CreateIpForwardEntry2(&forward_row) } {
match unsafe { CreateIpForwardEntry2(&forward_row) }.ok() {
Ok(_) => Some(forward_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -131,7 +131,7 @@ impl IphlpNetworkAdapterInfo {
forward_row.Protocol = MIB_IPPROTO_NT_STATIC;
forward_row.Origin = NlroManual;

match unsafe { CreateIpForwardEntry2(&forward_row) } {
match unsafe { CreateIpForwardEntry2(&forward_row) }.ok() {
Ok(_) => Some(forward_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -174,7 +174,7 @@ impl IphlpNetworkAdapterInfo {
forward_row.Protocol = MIB_IPPROTO_NT_STATIC;
forward_row.Origin = NlroManual;

match unsafe { CreateIpForwardEntry2(&forward_row) } {
match unsafe { CreateIpForwardEntry2(&forward_row) }.ok() {
Ok(_) => Some(forward_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down
4 changes: 2 additions & 2 deletions src/netlib/ip_helper/network_adapter_info/ndp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl IphlpNetworkAdapterInfo {
set_is_unreachable(&mut net_row, true);
}

match unsafe { CreateIpNetEntry2(&net_row) } {
match unsafe { CreateIpNetEntry2(&net_row) }.ok() {
Ok(_) => Some(net_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -99,7 +99,7 @@ impl IphlpNetworkAdapterInfo {
set_is_unreachable(&mut net_row, true);
}

match unsafe { CreateIpNetEntry2(&net_row) } {
match unsafe { CreateIpNetEntry2(&net_row) }.ok() {
Ok(_) => Some(net_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down
8 changes: 4 additions & 4 deletions src/netlib/ip_helper/network_adapter_info/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl IphlpNetworkAdapterInfo {
forward_row.Protocol = MIB_IPPROTO_NT_STATIC;
forward_row.Origin = NlroManual;

match unsafe { CreateIpForwardEntry2(&forward_row) } {
match unsafe { CreateIpForwardEntry2(&forward_row) }.ok() {
Ok(_) => ret_val.push_back(forward_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl IphlpNetworkAdapterInfo {
forward_row.Protocol = MIB_IPPROTO_NT_STATIC;
forward_row.Origin = NlroManual;

match unsafe { CreateIpForwardEntry2(&forward_row) } {
match unsafe { CreateIpForwardEntry2(&forward_row) }.ok() {
Ok(_) => return_value.push_back(forward_row),
Err(err) => {
if err == ERROR_OBJECT_ALREADY_EXISTS.into() {
Expand Down Expand Up @@ -181,7 +181,7 @@ impl IphlpNetworkAdapterInfo {
pub fn reset_adapter_routes(&self) -> bool {
let mut table: *mut MIB_IPFORWARD_TABLE2 = std::ptr::null_mut();

match unsafe { GetIpForwardTable2(AF_UNSPEC, &mut table) } {
match unsafe { GetIpForwardTable2(AF_UNSPEC, &mut table) }.ok() {
Ok(_) => {
let num_entries = unsafe { (*table).NumEntries };

Expand All @@ -193,7 +193,7 @@ impl IphlpNetworkAdapterInfo {
}
}

let _ = unsafe { FreeMibTable(table as *mut _) };
unsafe { FreeMibTable(table as *mut _) };
true
}
Err(_) => false,
Expand Down
17 changes: 7 additions & 10 deletions src/netlib/ip_helper/network_adapter_info/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl IphlpNetworkAdapterInfo {
}

// Free interface table
let _ = unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };

ret_val
}
Expand Down Expand Up @@ -196,8 +196,7 @@ impl IphlpNetworkAdapterInfo {
if IfLuid::from(unsafe { (*entry_ptr).InterfaceLuid }) == luid {
let result =
unsafe { IphlpNetworkAdapterInfo::new(current, entry_ptr) };
let _ =
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
return Some(result);
}
}
Expand All @@ -221,7 +220,7 @@ impl IphlpNetworkAdapterInfo {
}

// Free interface table
let _ = unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };

None
}
Expand Down Expand Up @@ -304,8 +303,7 @@ impl IphlpNetworkAdapterInfo {
{
let result =
unsafe { IphlpNetworkAdapterInfo::new(current, entry_ptr) };
let _ =
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
return Some(result);
}
}
Expand All @@ -329,7 +327,7 @@ impl IphlpNetworkAdapterInfo {
}

// Free interface table
let _ = unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };

None
}
Expand Down Expand Up @@ -414,8 +412,7 @@ impl IphlpNetworkAdapterInfo {
{
let result =
unsafe { IphlpNetworkAdapterInfo::new(current, entry_ptr) };
let _ =
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
return Some(result);
}
}
Expand All @@ -439,7 +436,7 @@ impl IphlpNetworkAdapterInfo {
}

// Free interface table
let _ = unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };
unsafe { FreeMibTable(mib_table as *const core::ffi::c_void) };

None
}
Expand Down
Loading