Use BNetworkDevice to get the current associated wireless network.
Use BNetworkDevice instead of using the driver settings api to get the associated wireless network. Also got rid of Settings::_PrepareRequest(), since it's no longer needed.
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include <driver_settings.h>
|
#include <driver_settings.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
|
#include <NetworkDevice.h>
|
||||||
#include <NetworkInterface.h>
|
#include <NetworkInterface.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
@@ -50,22 +51,6 @@ Settings::~Settings()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
Settings::_PrepareRequest(struct ifreq& request)
|
|
||||||
{
|
|
||||||
// This function is used for talking direct to the stack.
|
|
||||||
// It´s used by _ShowConfiguration.
|
|
||||||
|
|
||||||
const char* name = fName.String();
|
|
||||||
|
|
||||||
if (strlen(name) > IF_NAMESIZE)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
strcpy(request.ifr_name, name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
GetDefaultGateway(BString& gateway)
|
GetDefaultGateway(BString& gateway)
|
||||||
{
|
{
|
||||||
@@ -132,6 +117,7 @@ Settings::ReadConfiguration()
|
|||||||
BNetworkInterface interface(fName);
|
BNetworkInterface interface(fName);
|
||||||
BNetworkInterfaceAddress address;
|
BNetworkInterfaceAddress address;
|
||||||
|
|
||||||
|
// TODO: We only get the first address
|
||||||
if (interface.GetAddressAt(0, address) != B_OK)
|
if (interface.GetAddressAt(0, address) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -150,51 +136,15 @@ Settings::ReadConfiguration()
|
|||||||
|
|
||||||
fWirelessNetwork.SetTo(NULL);
|
fWirelessNetwork.SetTo(NULL);
|
||||||
|
|
||||||
BPath path;
|
BNetworkDevice networkDevice(fName);
|
||||||
find_directory(B_COMMON_SETTINGS_DIRECTORY, &path);
|
if (networkDevice.IsWireless()) {
|
||||||
path.Append("network");
|
uint32 networkIndex = 0;
|
||||||
path.Append("interfaces");
|
wireless_network wirelessNetwork;
|
||||||
|
// TODO: We only get the first associated network for now
|
||||||
void* handle = load_driver_settings(path.Path());
|
if (networkDevice.GetNextAssociatedNetwork(networkIndex,
|
||||||
if (handle != NULL) {
|
wirelessNetwork) == B_OK) {
|
||||||
const driver_settings* settings = get_driver_settings(handle);
|
fWirelessNetwork.SetTo(wirelessNetwork.name);
|
||||||
if (settings != NULL) {
|
|
||||||
for (int32 i = 0; i < settings->parameter_count; i++) {
|
|
||||||
driver_parameter& top = settings->parameters[i];
|
|
||||||
if (!strcmp(top.name, "interface")) {
|
|
||||||
// The name of the interface can either be the value of
|
|
||||||
// the "interface" parameter, or a separate "name" parameter
|
|
||||||
const char* name = NULL;
|
|
||||||
if (top.value_count > 0) {
|
|
||||||
name = top.values[0];
|
|
||||||
if (fName != name)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// search "network" parameter
|
|
||||||
for (int32 j = 0; j < top.parameter_count; j++) {
|
|
||||||
driver_parameter& sub = top.parameters[j];
|
|
||||||
if (name == NULL && !strcmp(sub.name, "name")
|
|
||||||
&& sub.value_count > 0) {
|
|
||||||
name = sub.values[0];
|
|
||||||
if (fName != sub.values[0])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strcmp(sub.name, "network")
|
|
||||||
&& sub.value_count > 0) {
|
|
||||||
fWirelessNetwork.SetTo(sub.values[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We found our interface
|
|
||||||
if (fName == name)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unload_driver_settings(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read resolv.conf for the dns.
|
// read resolv.conf for the dns.
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ public:
|
|||||||
void ReadConfiguration();
|
void ReadConfiguration();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _PrepareRequest(struct ifreq& request);
|
|
||||||
|
|
||||||
BString fIP;
|
BString fIP;
|
||||||
BString fGateway;
|
BString fGateway;
|
||||||
BString fNetmask;
|
BString fNetmask;
|
||||||
|
|||||||
Reference in New Issue
Block a user