From debc7b2198275dcb55e9c7f162cffcc16a971529 Mon Sep 17 00:00:00 2001 From: Brian Kellogg Date: Sun, 11 Dec 2022 13:40:40 -0500 Subject: [PATCH] updating to support ArrayVec crate changes, I think I found a simpler way of converting u128s to IPv6 but still don't completely understand it --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/mutate.rs | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47d25cf..10db5b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,7 +244,7 @@ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "lin_fh" -version = "0.3.1" +version = "0.3.2" dependencies = [ "arrayvec", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 8e46042..7c916fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lin_fh" -version = "0.3.1" +version = "0.3.2" authors = ["brian kellogg "] edition = "2021" diff --git a/src/mutate.rs b/src/mutate.rs index 832b3bf..fc4fcfa 100644 --- a/src/mutate.rs +++ b/src/mutate.rs @@ -1,5 +1,4 @@ extern crate chrono; // DateTime manipulation -extern crate arrayvec; use chrono::offset::Utc; use chrono::DateTime; @@ -62,9 +61,11 @@ pub fn to_int8(num: &str) -> i8 { Therefore have to break the 128bit value into 4 dwords, reverse them and recombine See: https://users.rust-lang.org/t/convert-hex-socket-notation-to-ip-and-port/33858/8 */ -pub fn u128_to_ipv6 (n: u128) -> std::io::Result<::std::net::Ipv6Addr> { - let u8s = n.to_be_bytes(); - Ok(::std::net::Ipv6Addr::from(u8s)) +pub fn u128_to_ipv6 (mut n: u128) -> std::io::Result<::std::net::Ipv6Addr> { + unsafe { &mut *(&mut n as *mut u128 as *mut [u32; 4]) } + .iter_mut() + .for_each(|n: &mut u32| *n = n.swap_bytes()); + Ok(::std::net::Ipv6Addr::from(n)) } // translate hex state to human readable