Skip to content

Commit

Permalink
Fix ipv6 on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dns13 committed Mar 5, 2024
1 parent a5c3531 commit 304d926
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ network-interface = "1.1"
openssl = "0.10"
openssl-sys = "0.9"
hex = "0.4.3"
current_platform = "0.2.0"
33 changes: 20 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crossterm::{
terminal::size,
};

use current_platform::CURRENT_PLATFORM;
use rustyline::{error::ReadlineError, CompletionType, Config, Editor};
use textplots::{Chart, Plot, Shape};

Expand Down Expand Up @@ -325,25 +326,31 @@ fn get_ipv6_link_local_from_serial(serial: u32) -> String {

let mut interface = None;

for itf in network_interfaces.iter() {
let addrs = &itf.addr;
for addr in addrs.iter() {
if addr.ip().is_ipv6() && !addr.ip().is_loopback() {
if &addr.ip().to_string()[..6] == "fe80::" {
interface = Some(itf.name.clone());
break;
if !CURRENT_PLATFORM.to_string().contains("windows") {
for itf in network_interfaces.iter() {
let addrs = &itf.addr;
for addr in addrs.iter() {
if addr.ip().is_ipv6() && !addr.ip().is_loopback() {
if &addr.ip().to_string()[..6] == "fe80::" {
interface = Some(itf.name.clone());
break;
}
}
}
}
}

let hex = format!("{:04x}", serial);
format!(
"fe80::b5:b1ff:fe{}:{}%{}",
&hex[..2],
&hex[2..],
interface.unwrap()
)
if interface.is_some() {
format!(
"fe80::b5:b1ff:fe{}:{}%{}",
&hex[..2],
&hex[2..],
interface.unwrap()
)
} else {
format!("fe80::b5:b1ff:fe{}:{}", &hex[..2], &hex[2..])
}
}

fn parse_shortcuts(command: &str) -> &str {
Expand Down

0 comments on commit 304d926

Please sign in to comment.