Skip to content

Commit

Permalink
fix: with the unspecified address, show all interface addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Aug 8, 2024
1 parent 85d378a commit 1dc4dff
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,11 @@ impl ServeSystem {
fn show_listening(cfg: &RtcServe, addr: &[SocketAddr], base: &str) {
let prefix = if cfg.tls.is_some() { "https" } else { "http" };

// prepare local addresses
let locals = local_ip_address::list_afinet_netifas()
// prepare interface addresses
let interfaces = local_ip_address::list_afinet_netifas()
.map(|addr| {
addr.into_iter()
.map(|(_name, addr)| addr)
.filter(|addr| addr.is_loopback())
.collect::<Vec<_>>()
})
.unwrap_or(vec![IpAddr::V4(Ipv4Addr::LOCALHOST)]);
Expand All @@ -173,7 +172,8 @@ fn show_listening(cfg: &RtcServe, addr: &[SocketAddr], base: &str) {

for addr in addr {
if addr.ip().is_unspecified() {
addresses.extend(locals.iter().filter_map(|ipaddr| match ipaddr {
// it the "unspecified" address, so we add the corresponding address family addresses
addresses.extend(interfaces.iter().filter_map(|ipaddr| match ipaddr {
IpAddr::V4(_ip) if addr.is_ipv4() => Some(SocketAddr::new(*ipaddr, addr.port())),
IpAddr::V6(_ip) if addr.is_ipv6() => Some(SocketAddr::new(*ipaddr, addr.port())),
_ => None,
Expand Down

0 comments on commit 1dc4dff

Please sign in to comment.