From b81d67ed0c2074f0b69afbed75104bde698550ca Mon Sep 17 00:00:00 2001 From: Jeremy Visser Date: Fri, 25 Dec 2020 17:02:39 +1100 Subject: [PATCH] NetworkStatus: print all interface addresses, not just the first The NetworkStatus applet by default only shows the first address on the interface, assuming IPv4 semantics and ignoring others. This assumption doesn't hold true for IPv6-enabled systems, which not only have both IPv4+IPv6 addresses, but typically multiple IPv6 addresses (link-local and global at a minimum). In addition, it's not unheard of to have multiple IPv4 addresses on a single interface, even though it's difficult to configure in Haiku at time of writing. This change loops through all available addresses and prints them in the status. No attention to ordering is made; future enhancements could include sorting IPv6 global/link-local, displaying the type, etc. Change-Id: Ib437e32fc878b5baafa8c2437659e10fb6fcffbf Reviewed-on: https://review.haiku-os.org/c/haiku/+/3550 Reviewed-by: Adrien Destugues --- src/apps/networkstatus/NetworkStatusView.cpp | 31 +++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/apps/networkstatus/NetworkStatusView.cpp b/src/apps/networkstatus/NetworkStatusView.cpp index fef76daf34..f27333b25f 100644 --- a/src/apps/networkstatus/NetworkStatusView.cpp +++ b/src/apps/networkstatus/NetworkStatusView.cpp @@ -342,18 +342,35 @@ NetworkStatusView::_ShowConfiguration(BMessage* message) if (!networkInterface.Exists()) return; - BNetworkInterfaceAddress address; - networkInterface.GetAddressAt(0, address); - // TODO: We should get all addresses, - // not just the first one. BString text(B_TRANSLATE("%ifaceName information:\n")); text.ReplaceFirst("%ifaceName", name); size_t boldLength = text.Length(); - text << "\n" << B_TRANSLATE("Address") << ": " << address.Address().ToString(); - text << "\n" << B_TRANSLATE("Broadcast") << ": " << address.Broadcast().ToString(); - text << "\n" << B_TRANSLATE("Netmask") << ": " << address.Mask().ToString(); + int32 numAddrs = networkInterface.CountAddresses(); + for (int32 i = 0; i < numAddrs; i++) { + BNetworkInterfaceAddress address; + networkInterface.GetAddressAt(i, address); + switch (address.Address().Family()) { + case AF_INET: + text << "\n" << B_TRANSLATE("IPv4 Address: ") + << address.Address().ToString() + << "\n" << B_TRANSLATE("Broadcast: ") + << address.Broadcast().ToString() + << "\n" << B_TRANSLATE("Netmask: ") + << address.Mask().ToString() + << "\n"; + break; + case AF_INET6: + text << "\n" << B_TRANSLATE("IPv6 Address: ") + << address.Address().ToString(); + << "/" << address.Mask().PrefixLength(); + << "\n"; + break; + default: + break; + } + } BAlert* alert = new BAlert(name, text.String(), B_TRANSLATE("OK")); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);