This commit is contained in:
Adam Ierymenko 2023-01-03 14:51:39 -05:00
parent bc02651613
commit 7dabeb9595

View file

@ -13,21 +13,22 @@ use std::hash::Hash;
pub struct LocalInterface(u128); pub struct LocalInterface(u128);
impl LocalInterface { impl LocalInterface {
#[inline]
#[cfg(unix)] #[cfg(unix)]
pub fn from_unix_interface_name(name: &str) -> Self { pub fn from_unix_interface_name(name: &str) -> Self {
let mut tmp = [0_u8; 16]; let mut tmp = 0u128.to_ne_bytes();
let nb = name.as_bytes(); let nb = name.as_bytes();
let l = nb.len(); let l = nb.len();
assert!(l <= 16); // do any *nix OSes have device names longer than 16 bytes? assert!(l <= 16); // do any *nix OSes have device names longer than 16 bytes?
tmp[..l].copy_from_slice(&nb[..l]); tmp[..l].copy_from_slice(&nb[..l]);
Self(u128::from_be_bytes(tmp)) Self(u128::from_ne_bytes(tmp))
} }
} }
impl ToString for LocalInterface { impl ToString for LocalInterface {
#[cfg(unix)] #[cfg(unix)]
fn to_string(&self) -> String { fn to_string(&self) -> String {
let b = self.0.to_be_bytes(); let b = self.0.to_ne_bytes();
let mut l = 0; let mut l = 0;
for bb in b.iter() { for bb in b.iter() {
if *bb > 0 { if *bb > 0 {
@ -41,6 +42,6 @@ impl ToString for LocalInterface {
#[cfg(windows)] #[cfg(windows)]
fn to_string(&self) -> String { fn to_string(&self) -> String {
zerotier_core_crypto::hex::to_string(&self.0.to_be_bytes()) zerotier_core_crypto::hex::to_string(&self.0.to_ne_bytes())
} }
} }