* 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());
|
||||
fNetMaskTextControl->SetText(settings->GetNetmask());
|
||||
|
||||
if (settings->GetAutoConfigure() == true)
|
||||
if (settings->AutoConfigure() == true)
|
||||
item = fTypeMenuField->Menu()->FindItem("DHCP");
|
||||
else
|
||||
item = fTypeMenuField->Menu()->FindItem("Static");
|
||||
if (item)
|
||||
item->SetMarked(true);
|
||||
|
||||
enableControls = settings->GetAutoConfigure() == false;
|
||||
enableControls = settings->AutoConfigure() == false;
|
||||
|
||||
if (settings->fNameservers.CountItems() >= 2) {
|
||||
if (settings->NameServers().CountItems() >= 2) {
|
||||
fSecondaryDNSTextControl->SetText(
|
||||
settings->fNameservers.ItemAt(1)->String());
|
||||
settings->NameServers().ItemAt(1)->String());
|
||||
}
|
||||
|
||||
if (settings->fNameservers.CountItems() >= 1) {
|
||||
if (settings->NameServers().CountItems() >= 1) {
|
||||
fPrimaryDNSTextControl->SetText(
|
||||
settings->fNameservers.ItemAt(0)->String());
|
||||
settings->NameServers().ItemAt(0)->String());
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,10 +351,10 @@ EthernetSettingsView::_ApplyControlsToConfiguration()
|
||||
fCurrentSettings->SetAutoConfigure(
|
||||
strcmp(fTypeMenuField->Menu()->FindMarked()->Label(), "DHCP") == 0);
|
||||
|
||||
fCurrentSettings->fNameservers.MakeEmpty();
|
||||
fCurrentSettings->fNameservers.AddItem(new BString(
|
||||
fCurrentSettings->NameServers().MakeEmpty();
|
||||
fCurrentSettings->NameServers().AddItem(new BString(
|
||||
fPrimaryDNSTextControl->Text()));
|
||||
fCurrentSettings->fNameservers.AddItem(new BString(
|
||||
fCurrentSettings->NameServers().AddItem(new BString(
|
||||
fSecondaryDNSTextControl->Text()));
|
||||
|
||||
fApplyButton->SetEnabled(false);
|
||||
@ -368,7 +368,7 @@ EthernetSettingsView::_SaveConfiguration()
|
||||
_ApplyControlsToConfiguration();
|
||||
_SaveDNSConfiguration();
|
||||
_SaveAdaptersConfiguration();
|
||||
if (fCurrentSettings->GetAutoConfigure())
|
||||
if (fCurrentSettings->AutoConfigure())
|
||||
_TriggerAutoConfig(fCurrentSettings->GetName());
|
||||
}
|
||||
|
||||
@ -393,10 +393,10 @@ EthernetSettingsView::_SaveDNSConfiguration()
|
||||
// loop over all adapters
|
||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||
Settings* settings = fSettings.ItemAt(i);
|
||||
for (int j = 0; j < settings->fNameservers.CountItems(); j++) {
|
||||
if (settings->fNameservers.ItemAt(j)->Length() > 0) {
|
||||
for (int j = 0; j < settings->NameServers().CountItems(); j++) {
|
||||
if (settings->NameServers().ItemAt(j)->Length() > 0) {
|
||||
content << "nameserver\t"
|
||||
<< settings->fNameservers.ItemAt(j)->String()
|
||||
<< settings->NameServers().ItemAt(j)->String()
|
||||
<< "\n";
|
||||
}
|
||||
}
|
||||
@ -418,7 +418,7 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
|
||||
// loop over all adapters. open the settings file only once,
|
||||
// append the settins of each non-autoconfiguring adapter
|
||||
for (int i = 0; i < fSettings.CountItems(); i++) {
|
||||
if (fSettings.ItemAt(i)->GetAutoConfigure())
|
||||
if (fSettings.ItemAt(i)->AutoConfigure())
|
||||
continue;
|
||||
|
||||
if (fp == NULL) {
|
||||
|
@ -13,9 +13,6 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.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 <resolv.h>
|
||||
#include <stdio.h>
|
||||
@ -32,12 +29,14 @@
|
||||
#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);
|
||||
fName = name;
|
||||
|
||||
ReadConfiguration();
|
||||
}
|
||||
|
||||
@ -88,10 +87,8 @@ Settings::ReadConfiguration()
|
||||
fIP = address;
|
||||
|
||||
// Obtain netmask.
|
||||
if (ioctl(fSocket, SIOCGIFNETMASK, &request,
|
||||
sizeof(request)) < 0) {
|
||||
if (ioctl(fSocket, SIOCGIFNETMASK, &request, sizeof(request)) < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
inetAddress = (sockaddr_in*)&request.ifr_mask;
|
||||
if (inet_ntop(AF_INET, &inetAddress->sin_addr, address,
|
||||
@ -111,7 +108,7 @@ Settings::ReadConfiguration()
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
void *buffer = malloc(size);
|
||||
void* buffer = malloc(size);
|
||||
if (buffer == NULL)
|
||||
return;
|
||||
|
||||
@ -122,13 +119,13 @@ Settings::ReadConfiguration()
|
||||
if (ioctl(fSocket, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
|
||||
return;
|
||||
|
||||
ifreq *interface = (ifreq *)buffer;
|
||||
ifreq *end = (ifreq *)((uint8 *)buffer + size);
|
||||
ifreq* interface = (ifreq*)buffer;
|
||||
ifreq* end = (ifreq*)((uint8*)buffer + size);
|
||||
|
||||
while (interface < end) {
|
||||
route_entry& route = interface->ifr_route;
|
||||
|
||||
if (route.flags & RTF_GATEWAY) {
|
||||
if ((route.flags & RTF_GATEWAY) != 0) {
|
||||
inetAddress = (sockaddr_in*)route.gateway;
|
||||
fGateway = inet_ntoa(inetAddress->sin_addr);
|
||||
}
|
||||
@ -141,8 +138,8 @@ Settings::ReadConfiguration()
|
||||
if (route.gateway != NULL)
|
||||
addressSize += route.gateway->sa_len;
|
||||
|
||||
interface = (ifreq *)((addr_t)interface +
|
||||
IF_NAMESIZE + sizeof(route_entry) + addressSize);
|
||||
interface = (ifreq *)((addr_t)interface + IF_NAMESIZE
|
||||
+ sizeof(route_entry) + addressSize);
|
||||
}
|
||||
|
||||
uint32 flags = 0;
|
||||
@ -152,14 +149,14 @@ Settings::ReadConfiguration()
|
||||
fAuto = (flags & IFF_AUTO_CONFIGURED) != 0;
|
||||
|
||||
// read resolv.conf for the dns.
|
||||
fNameservers.MakeEmpty();
|
||||
fNameServers.MakeEmpty();
|
||||
|
||||
res_init();
|
||||
res_state state = __res_state();
|
||||
|
||||
if (state != NULL) {
|
||||
for (int i = 0; i < state->nscount; i++) {
|
||||
fNameservers.AddItem(
|
||||
fNameServers.AddItem(
|
||||
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.
|
||||
*
|
||||
* Author:
|
||||
@ -8,37 +8,42 @@
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
|
||||
#include <ObjectList.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
Settings(const char* name);
|
||||
virtual ~Settings();
|
||||
public:
|
||||
Settings(const char* name);
|
||||
virtual ~Settings();
|
||||
|
||||
void SetName(BString name);
|
||||
void SetIP(BString ip) {fIP = ip; }
|
||||
void SetGateway(BString ip) {fGateway = ip; }
|
||||
void SetNetmask(BString ip) {fNetmask = ip; }
|
||||
void SetAutoConfigure(bool t) {fAuto = t; }
|
||||
|
||||
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();
|
||||
void SetIP(BString ip) { fIP = ip; }
|
||||
void SetGateway(BString ip) { fGateway = ip; }
|
||||
void SetNetmask(BString ip) { fNetmask = ip; }
|
||||
void SetAutoConfigure(bool autoConfigure)
|
||||
{ fAuto = autoConfigure; }
|
||||
|
||||
|
||||
private:
|
||||
bool _PrepareRequest(struct ifreq& request);
|
||||
BString fIP;
|
||||
BString fGateway;
|
||||
BString fNetmask;
|
||||
BString fName;
|
||||
int fSocket;
|
||||
bool fAuto;
|
||||
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 AutoConfigure() { return fAuto; }
|
||||
|
||||
BObjectList<BString>& NameServers() { return fNameServers; }
|
||||
|
||||
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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user