Network: Fix associated networks, support store by MAC.
* The associated networks are now selected by address, not their name. * Storing the settings now stores the address, too. * This fixes #10001.
This commit is contained in:
parent
e3beee6b66
commit
5243ff9403
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
||||
* Copyright 2004-2013 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
#include "EthernetSettingsView.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -368,9 +370,15 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
||||
BMenu* menu = fNetworkMenuField->Menu();
|
||||
menu->RemoveItems(0, menu->CountItems(), true);
|
||||
|
||||
std::set<BNetworkAddress> associated;
|
||||
BNetworkAddress address;
|
||||
uint32 cookie = 0;
|
||||
while (device.GetNextAssociatedNetwork(cookie, address) == B_OK)
|
||||
associated.insert(address);
|
||||
|
||||
wireless_network network;
|
||||
int32 count = 0;
|
||||
uint32 cookie = 0;
|
||||
cookie = 0;
|
||||
while (device.GetNextNetwork(cookie, network) == B_OK) {
|
||||
BMessage* message = new BMessage(kMsgNetwork);
|
||||
message->AddString("device", device.Name());
|
||||
@ -379,7 +387,7 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
||||
BMenuItem* item = new WirelessNetworkMenuItem(network.name,
|
||||
network.signal_strength,
|
||||
(network.flags & B_NETWORK_IS_ENCRYPTED) != 0, message);
|
||||
if (fCurrentSettings->WirelessNetwork() == network.name)
|
||||
if (associated.find(network.address) != associated.end())
|
||||
item->SetMarked(true);
|
||||
menu->AddItem(item);
|
||||
|
||||
@ -446,16 +454,6 @@ EthernetSettingsView::_ApplyControlsToConfiguration()
|
||||
fCurrentSettings->SetNetmask(fNetMaskTextControl->Text());
|
||||
fCurrentSettings->SetGateway(fGatewayTextControl->Text());
|
||||
|
||||
if (!fNetworkMenuField->IsHidden(fNetworkMenuField)) {
|
||||
if (fNetworkMenuField->Menu()->ItemAt(0)->IsMarked()) {
|
||||
fCurrentSettings->SetWirelessNetwork(NULL);
|
||||
} else {
|
||||
BMenuItem* item = fNetworkMenuField->Menu()->FindMarked();
|
||||
if (item != NULL)
|
||||
fCurrentSettings->SetWirelessNetwork(item->Label());
|
||||
}
|
||||
}
|
||||
|
||||
fCurrentSettings->SetAutoConfigure(
|
||||
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(),
|
||||
B_TRANSLATE("DHCP")) == 0);
|
||||
@ -539,7 +537,8 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||
Settings* settings = fSettings.ItemAt(i);
|
||||
|
||||
if (settings->AutoConfigure() && settings->WirelessNetwork() == "")
|
||||
std::vector<wireless_network> networks = settings->WirelessNetworks();
|
||||
if (settings->AutoConfigure() && networks.empty())
|
||||
continue;
|
||||
|
||||
if (fp == NULL) {
|
||||
@ -564,9 +563,14 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
||||
fprintf(fp, "\t\tmask\t%s\n", settings->Netmask());
|
||||
fprintf(fp, "\t}\n");
|
||||
}
|
||||
if (settings->WirelessNetwork() != "") {
|
||||
fprintf(fp, "\tnetwork\t%s\n",
|
||||
settings->WirelessNetwork().String());
|
||||
if (!networks.empty()) {
|
||||
for (size_t index = 0; index < networks.size(); index++) {
|
||||
wireless_network& network = networks[index];
|
||||
fprintf(fp, "\tnetwork %s {\n", network.name);
|
||||
fprintf(fp, "\t\tmac\t%s\n",
|
||||
network.address.ToString().String());
|
||||
fprintf(fp, "\t}\n");
|
||||
}
|
||||
}
|
||||
fprintf(fp, "}\n\n");
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
||||
* Copyright 2004-2013 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -34,23 +34,6 @@
|
||||
#include <AutoDeleter.h>
|
||||
|
||||
|
||||
Settings::Settings(const char* name)
|
||||
:
|
||||
fAuto(true),
|
||||
fDisabled(false),
|
||||
fNameServers(5, true)
|
||||
{
|
||||
fName = name;
|
||||
|
||||
ReadConfiguration();
|
||||
}
|
||||
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static status_t
|
||||
GetDefaultGateway(BString& gateway)
|
||||
{
|
||||
@ -111,6 +94,44 @@ GetDefaultGateway(BString& gateway)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Settings::Settings(const char* name)
|
||||
:
|
||||
fAuto(true),
|
||||
fDisabled(false),
|
||||
fNameServers(5, true)
|
||||
{
|
||||
fName = name;
|
||||
|
||||
ReadConfiguration();
|
||||
}
|
||||
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! Returns all associated wireless networks. */
|
||||
std::vector<wireless_network>
|
||||
Settings::WirelessNetworks()
|
||||
{
|
||||
std::vector<wireless_network> networks;
|
||||
|
||||
BNetworkDevice device(fName);
|
||||
if (device.IsWireless()) {
|
||||
wireless_network wirelessNetwork;
|
||||
uint32 cookie = 0;
|
||||
while (device.GetNextAssociatedNetwork(cookie, wirelessNetwork) == B_OK)
|
||||
networks.push_back(wirelessNetwork);
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::ReadConfiguration()
|
||||
{
|
||||
@ -132,21 +153,6 @@ Settings::ReadConfiguration()
|
||||
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();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2004-2010 Haiku Inc. All rights reserved.
|
||||
* Copyright 2004-2013 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@ -10,6 +10,9 @@
|
||||
#define SETTINGS_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <NetworkDevice.h>
|
||||
#include <ObjectList.h>
|
||||
#include <String.h>
|
||||
|
||||
@ -31,8 +34,6 @@ public:
|
||||
{ fAuto = autoConfigure; }
|
||||
void SetDisabled(bool disabled)
|
||||
{ fDisabled = disabled; }
|
||||
void SetWirelessNetwork(const char* name)
|
||||
{ fWirelessNetwork.SetTo(name); }
|
||||
|
||||
const char* IP() { return fIP.String(); }
|
||||
const char* Gateway() { return fGateway.String(); }
|
||||
@ -41,7 +42,8 @@ public:
|
||||
const char* Domain() { return fDomain.String(); }
|
||||
bool AutoConfigure() { return fAuto; }
|
||||
bool IsDisabled() { return fDisabled; }
|
||||
const BString& WirelessNetwork() { return fWirelessNetwork; }
|
||||
|
||||
std::vector<wireless_network> WirelessNetworks();
|
||||
|
||||
BObjectList<BString>& NameServers() { return fNameServers; }
|
||||
|
||||
@ -56,7 +58,6 @@ private:
|
||||
bool fAuto;
|
||||
bool fDisabled;
|
||||
BObjectList<BString> fNameServers;
|
||||
BString fWirelessNetwork;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user