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 Settings::ReadConfiguration() { BNetworkInterface interface(fName); BNetworkInterfaceAddress address; // TODO: We only get the first address if (interface.GetAddressAt(0, address) != B_OK) return; fIP = address.Address().ToString(); fNetmask = address.Mask().ToString(); if (GetDefaultGateway(fGateway) != B_OK) return; uint32 flags = interface.Flags(); fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0; fDisabled = (flags & IFF_UP) == 0; // Read wireless network from interfaces fWirelessNetwork.SetTo(NULL); BNetworkDevice networkDevice(fName); if (networkDevice.IsWireless()) { uint32 networkIndex = 0; wireless_network wirelessNetwork; // TODO: We only get the first associated network for now if (networkDevice.GetNextAssociatedNetwork(networkIndex, wirelessNetwork) == B_OK) { fWirelessNetwork.SetTo(wirelessNetwork.name); } } // read resolv.conf for the dns. fNameServers.MakeEmpty(); res_init(); res_state state = __res_state(); if (state != NULL) { for (int i = 0; i < state->nscount; i++) { fNameServers.AddItem( new BString(inet_ntoa(state->nsaddr_list[i].sin_addr))); } fDomain = state->dnsrch[0]; } }
void Settings::ReadConfiguration() { BNetworkInterface interface(fName); BNetworkAddress hardwareAddress; if (interface.GetHardwareAddress(hardwareAddress) != B_OK) return; fHardwareAddress = hardwareAddress.ToString(); BNetworkInterfaceAddress address; // TODO: We only get the first address if (interface.GetAddressAt(0, address) != B_OK) return; fIP = address.Address().ToString(); fNetmask = address.Mask().ToString(); int family = AF_INET; if (address.Address().Family() != AF_UNSPEC) family = address.Address().Family(); BNetworkAddress gatewayAddress; if (interface.GetDefaultRoute(family, gatewayAddress) != B_OK) return; fGateway = gatewayAddress.ToString(); uint32 flags = interface.Flags(); fAuto = (flags & (IFF_AUTO_CONFIGURED | IFF_CONFIGURING)) != 0; fDisabled = (flags & IFF_UP) == 0; // read resolv.conf for the dns. fNameServers.MakeEmpty(); res_init(); res_state state = __res_state(); if (state != NULL) { for (int i = 0; i < state->nscount; i++) { fNameServers.AddItem( new BString(inet_ntoa(state->nsaddr_list[i].sin_addr))); } fDomain = state->dnsrch[0]; } }
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); }