void list_interface_addresses(BNetworkInterface& interface, uint32 flags) { int32 count = interface.CountAddresses(); for (int32 i = 0; i < count; i++) { BNetworkInterfaceAddress address; if (interface.GetAddressAt(i, address) != B_OK) break; const address_family* family = address_family_for(address.Address().sa_family); printf("\t%s addr: %s", family->name, BNetworkAddress(address.Address()).ToString().String()); if ((flags & IFF_BROADCAST) != 0) { printf(", Bcast: %s", BNetworkAddress(address.Broadcast()).ToString().String()); } switch (family->preferred_format) { case PREFER_OUTPUT_MASK: printf(", Mask: %s", BNetworkAddress(address.Mask()).ToString().String()); break; case PREFER_OUTPUT_PREFIX_LENGTH: printf(", Prefix Length: %zu", BNetworkAddress(address.Mask()).PrefixLength()); break; } putchar('\n'); } }
void NetworkStatusView::_ShowConfiguration(BMessage* message) { const char* name; if (message->FindString("interface", &name) != B_OK) return; BNetworkInterface networkInterface(name); 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(); BAlert* alert = new BAlert(name, text.String(), B_TRANSLATE("OK")); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); BTextView* view = alert->TextView(); BFont font; view->SetStylable(true); view->GetFont(&font); font.SetFace(B_BOLD_FACE); view->SetFontAndColor(0, boldLength, &font); alert->Go(NULL); }