Skip to content

Commit

Permalink
chore: Fix breaking changes caused by microsoft/windows-rs#2890
Browse files Browse the repository at this point in the history
  • Loading branch information
dilawar committed Mar 12, 2024
1 parent 073c9ac commit fa264a1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions src/ndisapi/static_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Ndisapi {
0,
KEY_READ,
&mut target_key,
)
).ok()
};

if result.is_err() {
Expand Down Expand Up @@ -313,7 +313,7 @@ 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 +330,7 @@ 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 +373,7 @@ impl Ndisapi {
KEY_WRITE,
&mut hkey,
)
};
}.ok();

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

result
Expand Down Expand Up @@ -471,7 +471,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 +559,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
10 changes: 5 additions & 5 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,7 +180,7 @@ 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] };
Expand Down Expand Up @@ -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 Down Expand Up @@ -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 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
6 changes: 3 additions & 3 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 Down

0 comments on commit fa264a1

Please sign in to comment.