-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConvertInterfaceLuidToIndex business
- Loading branch information
Showing
4 changed files
with
66 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::{io, mem}; | ||
use windows_sys::core::GUID; | ||
use windows_sys::Win32::NetworkManagement::IpHelper::{ | ||
ConvertInterfaceAliasToLuid, ConvertInterfaceLuidToAlias, ConvertInterfaceLuidToGuid, ConvertInterfaceLuidToIndex, | ||
}; | ||
use windows_sys::Win32::NetworkManagement::Ndis::NET_LUID_LH; | ||
|
||
pub fn luid_to_alias(luid: &NET_LUID_LH) -> io::Result<Vec<u16>> { | ||
// IF_MAX_STRING_SIZE + 1 | ||
let mut alias = vec![0; 257]; | ||
|
||
match unsafe { ConvertInterfaceLuidToAlias(luid, alias.as_mut_ptr(), alias.len()) } { | ||
0 => Ok(alias), | ||
err => Err(io::Error::from_raw_os_error(err as _)), | ||
} | ||
} | ||
|
||
pub fn alias_to_luid(alias: &[u16]) -> io::Result<NET_LUID_LH> { | ||
let mut luid = unsafe { mem::zeroed() }; | ||
|
||
match unsafe { ConvertInterfaceAliasToLuid(alias.as_ptr(), &mut luid) } { | ||
0 => Ok(luid), | ||
err => Err(io::Error::from_raw_os_error(err as _)), | ||
} | ||
} | ||
pub fn luid_to_index(luid: &NET_LUID_LH) -> io::Result<u32> { | ||
let mut index = 0; | ||
|
||
match unsafe { ConvertInterfaceLuidToIndex(luid, &mut index) } { | ||
0 => Ok(index), | ||
err => Err(io::Error::from_raw_os_error(err as _)), | ||
} | ||
} | ||
|
||
pub fn luid_to_guid(luid: &NET_LUID_LH) -> io::Result<GUID> { | ||
let mut guid = unsafe { mem::zeroed() }; | ||
|
||
match unsafe { ConvertInterfaceLuidToGuid(luid, &mut guid) } { | ||
0 => Ok(guid), | ||
err => Err(io::Error::from_raw_os_error(err as _)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ | |
mod adapter; | ||
mod error; | ||
mod ffi; | ||
mod log; | ||
mod packet; | ||
mod session; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters