Fixed an issue where an internet adaptor has no adress

This commit is contained in:
Alex Emmet 2025-11-30 17:29:58 +00:00
commit 8dd376e050
2 changed files with 12 additions and 8 deletions

View file

@ -118,12 +118,14 @@ async fn main() {
let mut ip = "0.0.0.0".to_string(); let mut ip = "0.0.0.0".to_string();
for iface in pnet::datalink::interfaces() { for iface in pnet::datalink::interfaces() {
let iface: NetworkInterface = iface; let iface: NetworkInterface = iface;
if iface.ips.len() > 0 {
let ipsv = format!("{}", iface.ips[0]); let ipsv = format!("{}", iface.ips[0]);
let ips: &str = ipsv.split('/').next().unwrap(); let ips: &str = ipsv.split('/').next().unwrap();
if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") { if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") {
ip = ips.to_string(); ip = ips.to_string();
} }
} }
}
if start(port).await { if start(port).await {
log_message(format("community_active", &[&ip, &port.to_string()])); log_message(format("community_active", &[&ip, &port.to_string()]));
} else { } else {

View file

@ -225,12 +225,14 @@ async fn run_http_server(port: u16) -> bool {
let mut ip = "0.0.0.0".to_string(); let mut ip = "0.0.0.0".to_string();
for iface in pnet::datalink::interfaces() { for iface in pnet::datalink::interfaces() {
let iface: NetworkInterface = iface; let iface: NetworkInterface = iface;
if iface.ips.len() > 0 {
let ipsv = format!("{}", iface.ips[0]); let ipsv = format!("{}", iface.ips[0]);
let ips: &str = ipsv.split('/').next().unwrap(); let ips: &str = ipsv.split('/').next().unwrap();
if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") { if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") {
ip = ips.to_string(); ip = ips.to_string();
} }
} }
}
let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).await; let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).await;
if let Err(e) = listener { if let Err(e) = listener {
log_message(format!("Failed to bind to port {}: {:?}", port, e)); log_message(format!("Failed to bind to port {}: {:?}", port, e));