* Some cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33995 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b258fd9105
commit
136e443291
@ -303,23 +303,23 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
|
|||||||
fGatewayTextControl->SetText(settings->GetGateway());
|
fGatewayTextControl->SetText(settings->GetGateway());
|
||||||
fNetMaskTextControl->SetText(settings->GetNetmask());
|
fNetMaskTextControl->SetText(settings->GetNetmask());
|
||||||
|
|
||||||
if (settings->GetAutoConfigure() == true)
|
if (settings->AutoConfigure() == true)
|
||||||
item = fTypeMenuField->Menu()->FindItem("DHCP");
|
item = fTypeMenuField->Menu()->FindItem("DHCP");
|
||||||
else
|
else
|
||||||
item = fTypeMenuField->Menu()->FindItem("Static");
|
item = fTypeMenuField->Menu()->FindItem("Static");
|
||||||
if (item)
|
if (item)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
enableControls = settings->GetAutoConfigure() == false;
|
enableControls = settings->AutoConfigure() == false;
|
||||||
|
|
||||||
if (settings->fNameservers.CountItems() >= 2) {
|
if (settings->NameServers().CountItems() >= 2) {
|
||||||
fSecondaryDNSTextControl->SetText(
|
fSecondaryDNSTextControl->SetText(
|
||||||
settings->fNameservers.ItemAt(1)->String());
|
settings->NameServers().ItemAt(1)->String());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings->fNameservers.CountItems() >= 1) {
|
if (settings->NameServers().CountItems() >= 1) {
|
||||||
fPrimaryDNSTextControl->SetText(
|
fPrimaryDNSTextControl->SetText(
|
||||||
settings->fNameservers.ItemAt(0)->String());
|
settings->NameServers().ItemAt(0)->String());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,10 +351,10 @@ EthernetSettingsView::_ApplyControlsToConfiguration()
|
|||||||
fCurrentSettings->SetAutoConfigure(
|
fCurrentSettings->SetAutoConfigure(
|
||||||
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(), "DHCP") == 0);
|
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(), "DHCP") == 0);
|
||||||
|
|
||||||
fCurrentSettings->fNameservers.MakeEmpty();
|
fCurrentSettings->NameServers().MakeEmpty();
|
||||||
fCurrentSettings->fNameservers.AddItem(new BString(
|
fCurrentSettings->NameServers().AddItem(new BString(
|
||||||
fPrimaryDNSTextControl->Text()));
|
fPrimaryDNSTextControl->Text()));
|
||||||
fCurrentSettings->fNameservers.AddItem(new BString(
|
fCurrentSettings->NameServers().AddItem(new BString(
|
||||||
fSecondaryDNSTextControl->Text()));
|
fSecondaryDNSTextControl->Text()));
|
||||||
|
|
||||||
fApplyButton->SetEnabled(false);
|
fApplyButton->SetEnabled(false);
|
||||||
@ -368,7 +368,7 @@ EthernetSettingsView::_SaveConfiguration()
|
|||||||
_ApplyControlsToConfiguration();
|
_ApplyControlsToConfiguration();
|
||||||
_SaveDNSConfiguration();
|
_SaveDNSConfiguration();
|
||||||
_SaveAdaptersConfiguration();
|
_SaveAdaptersConfiguration();
|
||||||
if (fCurrentSettings->GetAutoConfigure())
|
if (fCurrentSettings->AutoConfigure())
|
||||||
_TriggerAutoConfig(fCurrentSettings->GetName());
|
_TriggerAutoConfig(fCurrentSettings->GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,10 +393,10 @@ EthernetSettingsView::_SaveDNSConfiguration()
|
|||||||
// loop over all adapters
|
// loop over all adapters
|
||||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||||
Settings* settings = fSettings.ItemAt(i);
|
Settings* settings = fSettings.ItemAt(i);
|
||||||
for (int j = 0; j < settings->fNameservers.CountItems(); j++) {
|
for (int j = 0; j < settings->NameServers().CountItems(); j++) {
|
||||||
if (settings->fNameservers.ItemAt(j)->Length() > 0) {
|
if (settings->NameServers().ItemAt(j)->Length() > 0) {
|
||||||
content << "nameserver\t"
|
content << "nameserver\t"
|
||||||
<< settings->fNameservers.ItemAt(j)->String()
|
<< settings->NameServers().ItemAt(j)->String()
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
|||||||
// loop over all adapters. open the settings file only once,
|
// loop over all adapters. open the settings file only once,
|
||||||
// append the settins of each non-autoconfiguring adapter
|
// append the settins of each non-autoconfiguring adapter
|
||||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||||
if (fSettings.ItemAt(i)->GetAutoConfigure())
|
if (fSettings.ItemAt(i)->AutoConfigure())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
|
@ -13,9 +13,6 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <net/if_dl.h>
|
|
||||||
#include <net/if_media.h>
|
|
||||||
#include <net/if_types.h>
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <resolv.h>
|
#include <resolv.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -32,12 +29,14 @@
|
|||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
|
|
||||||
Settings::Settings(const char *name)
|
Settings::Settings(const char* name)
|
||||||
:
|
:
|
||||||
fAuto(true)
|
fAuto(true),
|
||||||
|
fNameServers(5, true)
|
||||||
{
|
{
|
||||||
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
fName = name;
|
fName = name;
|
||||||
|
|
||||||
ReadConfiguration();
|
ReadConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,10 +87,8 @@ Settings::ReadConfiguration()
|
|||||||
fIP = address;
|
fIP = address;
|
||||||
|
|
||||||
// Obtain netmask.
|
// Obtain netmask.
|
||||||
if (ioctl(fSocket, SIOCGIFNETMASK, &request,
|
if (ioctl(fSocket, SIOCGIFNETMASK, &request, sizeof(request)) < 0)
|
||||||
sizeof(request)) < 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
inetAddress = (sockaddr_in*)&request.ifr_mask;
|
inetAddress = (sockaddr_in*)&request.ifr_mask;
|
||||||
if (inet_ntop(AF_INET, &inetAddress->sin_addr, address,
|
if (inet_ntop(AF_INET, &inetAddress->sin_addr, address,
|
||||||
@ -111,7 +108,7 @@ Settings::ReadConfiguration()
|
|||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void *buffer = malloc(size);
|
void* buffer = malloc(size);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -122,13 +119,13 @@ Settings::ReadConfiguration()
|
|||||||
if (ioctl(fSocket, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
|
if (ioctl(fSocket, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ifreq *interface = (ifreq *)buffer;
|
ifreq* interface = (ifreq*)buffer;
|
||||||
ifreq *end = (ifreq *)((uint8 *)buffer + size);
|
ifreq* end = (ifreq*)((uint8*)buffer + size);
|
||||||
|
|
||||||
while (interface < end) {
|
while (interface < end) {
|
||||||
route_entry& route = interface->ifr_route;
|
route_entry& route = interface->ifr_route;
|
||||||
|
|
||||||
if (route.flags & RTF_GATEWAY) {
|
if ((route.flags & RTF_GATEWAY) != 0) {
|
||||||
inetAddress = (sockaddr_in*)route.gateway;
|
inetAddress = (sockaddr_in*)route.gateway;
|
||||||
fGateway = inet_ntoa(inetAddress->sin_addr);
|
fGateway = inet_ntoa(inetAddress->sin_addr);
|
||||||
}
|
}
|
||||||
@ -141,8 +138,8 @@ Settings::ReadConfiguration()
|
|||||||
if (route.gateway != NULL)
|
if (route.gateway != NULL)
|
||||||
addressSize += route.gateway->sa_len;
|
addressSize += route.gateway->sa_len;
|
||||||
|
|
||||||
interface = (ifreq *)((addr_t)interface +
|
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
|
||||||
IF_NAMESIZE + sizeof(route_entry) + addressSize);
|
+ sizeof(route_entry) + addressSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 flags = 0;
|
uint32 flags = 0;
|
||||||
@ -152,14 +149,14 @@ Settings::ReadConfiguration()
|
|||||||
fAuto = (flags & IFF_AUTO_CONFIGURED) != 0;
|
fAuto = (flags & IFF_AUTO_CONFIGURED) != 0;
|
||||||
|
|
||||||
// read resolv.conf for the dns.
|
// read resolv.conf for the dns.
|
||||||
fNameservers.MakeEmpty();
|
fNameServers.MakeEmpty();
|
||||||
|
|
||||||
res_init();
|
res_init();
|
||||||
res_state state = __res_state();
|
res_state state = __res_state();
|
||||||
|
|
||||||
if (state != NULL) {
|
if (state != NULL) {
|
||||||
for (int i = 0; i < state->nscount; i++) {
|
for (int i = 0; i < state->nscount; i++) {
|
||||||
fNameservers.AddItem(
|
fNameServers.AddItem(
|
||||||
new BString(inet_ntoa(state->nsaddr_list[i].sin_addr)));
|
new BString(inet_ntoa(state->nsaddr_list[i].sin_addr)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2007 Haiku Inc. All rights reserved.
|
* Copyright 2004-2009 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Author:
|
* Author:
|
||||||
@ -8,37 +8,42 @@
|
|||||||
#ifndef SETTINGS_H
|
#ifndef SETTINGS_H
|
||||||
#define SETTINGS_H
|
#define SETTINGS_H
|
||||||
|
|
||||||
|
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
Settings(const char* name);
|
Settings(const char* name);
|
||||||
virtual ~Settings();
|
virtual ~Settings();
|
||||||
|
|
||||||
void SetName(BString name);
|
void SetIP(BString ip) { fIP = ip; }
|
||||||
void SetIP(BString ip) {fIP = ip; }
|
void SetGateway(BString ip) { fGateway = ip; }
|
||||||
void SetGateway(BString ip) {fGateway = ip; }
|
void SetNetmask(BString ip) { fNetmask = ip; }
|
||||||
void SetNetmask(BString ip) {fNetmask = ip; }
|
void SetAutoConfigure(bool autoConfigure)
|
||||||
void SetAutoConfigure(bool t) {fAuto = t; }
|
{ fAuto = autoConfigure; }
|
||||||
|
|
||||||
const char* GetIP() {return fIP.String(); }
|
|
||||||
const char* GetGateway() {return fGateway.String(); }
|
|
||||||
const char* GetNetmask() {return fNetmask.String(); }
|
|
||||||
const char* GetName() {return fName.String(); }
|
|
||||||
bool GetAutoConfigure() {return fAuto; }
|
|
||||||
BObjectList<BString> fNameservers;
|
|
||||||
void ReadConfiguration();
|
|
||||||
|
|
||||||
|
const char* GetIP() { return fIP.String(); }
|
||||||
private:
|
const char* GetGateway() { return fGateway.String(); }
|
||||||
bool _PrepareRequest(struct ifreq& request);
|
const char* GetNetmask() { return fNetmask.String(); }
|
||||||
BString fIP;
|
const char* GetName() { return fName.String(); }
|
||||||
BString fGateway;
|
bool AutoConfigure() { return fAuto; }
|
||||||
BString fNetmask;
|
|
||||||
BString fName;
|
BObjectList<BString>& NameServers() { return fNameServers; }
|
||||||
int fSocket;
|
|
||||||
bool fAuto;
|
void ReadConfiguration();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _PrepareRequest(struct ifreq& request);
|
||||||
|
|
||||||
|
BString fIP;
|
||||||
|
BString fGateway;
|
||||||
|
BString fNetmask;
|
||||||
|
BString fName;
|
||||||
|
int fSocket;
|
||||||
|
bool fAuto;
|
||||||
|
BObjectList<BString> fNameServers;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SETTINGS_H */
|
#endif /* SETTINGS_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user