From 44fb26c3bc0b692d92a8599783d9cbcd8dd55a78 Mon Sep 17 00:00:00 2001 From: masterflitzer <60170948+masterflitzer@users.noreply.github.com> Date: Thu, 18 May 2023 16:16:11 +0200 Subject: [PATCH] fix build error (linux/arm/whatever) (#30) * implement EUI-48 -> EUI-64 (modified) myself: instead of relying on to_modified_eui64 from advmac, because it doesn't compile on arm * switch from mac_address2 to mac_address due to a bug returning loopback mac on non-windows platforms * make ipv6 selection more readable in code --- Cargo.lock | 107 ++++++++++++++++------------------------------------- Cargo.toml | 3 +- src/ip.rs | 41 ++++++++++++-------- 3 files changed, 57 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7935f04..0b4ae77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,17 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "advmac" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c1bfd911d1173023132c681f7434ed956ec5459d7520b4f85331fc00d93bf0" -dependencies = [ - "arrayvec", - "rand", - "serde", -] - [[package]] name = "anstream" version = "0.3.2" @@ -62,15 +51,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -dependencies = [ - "serde", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -171,11 +151,10 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" name = "ddns_cloudflare" version = "0.4.0" dependencies = [ - "advmac", "clap", "directories", "local-ip-address", - "mac_address2", + "mac_address", "reqwest", "serde", "serde_json", @@ -411,9 +390,9 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.2" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" +checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7" dependencies = [ "http", "hyper", @@ -530,15 +509,13 @@ dependencies = [ ] [[package]] -name = "mac_address2" -version = "2.0.0" +name = "mac_address" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ba7721418458c854e2591dd131023095e2ab63f87580857062dfa031e5f760" +checksum = "b238e3235c8382b7653c6408ed1b08dd379bdb9fdf990fb0bbae3db2cc0ae963" dependencies = [ "nix", - "thiserror", - "widestring", - "windows-sys 0.48.0", + "winapi", ] [[package]] @@ -549,9 +526,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" -version = "0.7.1" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ "autocfg", ] @@ -601,16 +578,15 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" dependencies = [ "bitflags", + "cc", "cfg-if", "libc", "memoffset", - "pin-utils", - "static_assertions", ] [[package]] @@ -678,9 +654,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ec6d5fe0b140acb27c9a0444118cf55bfbb4e0b259739429abb4521dd67c16" +checksum = "fa1fb82fc0c281dd9671101b66b771ebbe1eaf967b96ac8740dcba4b70005ca8" dependencies = [ "unicode-ident", ] @@ -694,24 +670,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -734,9 +692,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.17" +version = "0.11.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13293b639a097af28fc8a90f22add145a9c954e49d77da06263d58cf44d5fb91" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" dependencies = [ "base64", "bytes", @@ -802,14 +760,14 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "c911ba11bc8433e811ce56fde130ccf32f5127cab0e0194e9c68c5a5b671791e" dependencies = [ "log", "ring", + "rustls-webpki", "sct", - "webpki", ] [[package]] @@ -821,6 +779,16 @@ dependencies = [ "base64", ] +[[package]] +name = "rustls-webpki" +version = "0.100.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.13" @@ -935,12 +903,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.10.0" @@ -1036,13 +998,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.23.4" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" +checksum = "e0d409377ff5b1e3ca6437aa86c1eb7d40c134bfec254e44c830defa92669db5" dependencies = [ "rustls", "tokio", - "webpki", ] [[package]] @@ -1280,12 +1241,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "widestring" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index facb636..a98c3cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,11 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -advmac = "1.0.3" clap = { version = "4.2.7", features = ["derive"] } directories = "5.0.1" local-ip-address = "0.5.3" -mac_address2 = "2.0.0" +mac_address = "1.1.4" reqwest = { version = "0.11.17", default-features = false, features = [ "json", "rustls-tls", diff --git a/src/ip.rs b/src/ip.rs index 03d395e..272fc6f 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -1,7 +1,6 @@ use crate::structs::{config::Config, Ipify}; -use advmac::MacAddr6; use local_ip_address::list_afinet_netifas; -use mac_address2::get_mac_address; +use mac_address::get_mac_address; use reqwest::Client as HttpClient; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; @@ -74,9 +73,7 @@ pub(crate) async fn determine_ipv6(config: &Config) -> Option { if config.ipv6.prefer_eui64 { let mac = get_mac_address().ok()?; - let eui48 = MacAddr6::new(mac?.bytes()); - let eui64 = eui48.to_modified_eui64(); - let suffix = eui64.to_array(); + let suffix = eui48_to_modified_eui64(&mac?.bytes())?; if let Some(x) = ipv6_addresses.iter().find(|ip| match split_ipv6(ip) { Some((_, s)) => s == suffix, None => false, @@ -85,22 +82,34 @@ pub(crate) async fn determine_ipv6(config: &Config) -> Option { }; } - if !config.ipv6.prefer_outgoing { - return ipv6_addresses - .into_iter() - .filter(|ip| ip != &ipv6) - .collect::>() - .first() - .cloned(); + if config.ipv6.prefer_outgoing { + return Some(ipv6); } - Some(ipv6) + return ipv6_addresses + .into_iter() + .filter(|ip| ip != &ipv6) + .collect::>() + .first() + .cloned(); } fn split_ipv6(ipv6: &Ipv6Addr) -> Option<([u8; 8], [u8; 8])> { let octets = ipv6.octets(); - let (octets_prefix, octets_suffix) = octets.split_at(8); - let prefix: [u8; 8] = octets_prefix.try_into().ok()?; - let suffix: [u8; 8] = octets_suffix.try_into().ok()?; + let (p, s) = octets.split_at(8); + let prefix: [u8; 8] = p.try_into().ok()?; + let suffix: [u8; 8] = s.try_into().ok()?; Some((prefix, suffix)) } + +fn eui48_to_modified_eui64(eui48: &[u8; 6]) -> Option<[u8; 8]> { + let (p, s) = eui48.split_at(3); + let prefix: [u8; 3] = p.try_into().ok()?; + let suffix: [u8; 3] = s.try_into().ok()?; + let eui64 = [ + prefix[0], prefix[1], prefix[2], 0xff, 0xfe, suffix[0], suffix[1], suffix[2], + ]; + let mut modified_eui64 = eui64; + modified_eui64[0] ^= 0b0000_0010; + Some(modified_eui64) +}