Skip to content

Commit

Permalink
updating to support ArrayVec crate changes, I think I found a simpler…
Browse files Browse the repository at this point in the history
… way of converting u128s to IPv6 but still don't completely understand it
  • Loading branch information
theflakes committed Dec 11, 2022
1 parent 9e1eeeb commit debc7b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lin_fh"
version = "0.3.1"
version = "0.3.2"
authors = ["brian kellogg <[email protected]>"]
edition = "2021"

Expand Down
9 changes: 5 additions & 4 deletions src/mutate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate chrono; // DateTime manipulation
extern crate arrayvec;

use chrono::offset::Utc;
use chrono::DateTime;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit debc7b2

Please sign in to comment.