Patch by Vegard Waerp: Added support for setting the the local domain in the

Network settings and setting the domain if received by DHCP.

Thanks a lot, closes #5619.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35938 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2010-03-23 23:58:41 +00:00
parent 9feca2b759
commit 0f87f52fad
5 changed files with 39 additions and 2 deletions
@@ -8,6 +8,7 @@
* Axel Dörfler
* Hugo Santos
* Philippe Saint-Pierre
* Vegard Wærp
*/
@@ -172,12 +173,17 @@ EthernetSettingsView::EthernetSettingsView()
layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 6);
layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 6);
fDomainTextControl = new BTextControl(TR("Domain:"), "", NULL);
SetupTextControl(fDomainTextControl);
layout->AddItem(fDomainTextControl->CreateLabelLayoutItem(), 0, 7);
layout->AddItem(fDomainTextControl->CreateTextViewLayoutItem(), 1, 7);
fErrorMessage = new BStringView("error", "");
fErrorMessage->SetAlignment(B_ALIGN_LEFT);
fErrorMessage->SetFont(be_bold_font);
fErrorMessage->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
layout->AddView(fErrorMessage, 1, 7);
layout->AddView(fErrorMessage, 1, 8);
// button group (TODO: move to window, but take care of
// enabling/disabling)
@@ -268,6 +274,7 @@ EthernetSettingsView::AttachedToWindow()
fGatewayTextControl->SetTarget(this);
fPrimaryDNSTextControl->SetTarget(this);
fSecondaryDNSTextControl->SetTarget(this);
fDomainTextControl->SetTarget(this);
fDeviceMenuField->Menu()->SetTargetForItems(this);
fTypeMenuField->Menu()->SetTargetForItems(this);
@@ -293,6 +300,7 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
fNetMaskTextControl->SetText("");
fPrimaryDNSTextControl->SetText("");
fSecondaryDNSTextControl->SetText("");
fDomainTextControl->SetText("");
bool enableControls = false;
fTypeMenuField->SetEnabled(settings != NULL);
@@ -325,6 +333,7 @@ EthernetSettingsView::_ShowConfiguration(Settings* settings)
fPrimaryDNSTextControl->SetText(
settings->NameServers().ItemAt(0)->String());
}
fDomainTextControl->SetText(settings->Domain());
}
_EnableTextControls(enableControls);
@@ -339,6 +348,7 @@ EthernetSettingsView::_EnableTextControls(bool enable)
fNetMaskTextControl->SetEnabled(enable);
fPrimaryDNSTextControl->SetEnabled(enable);
fSecondaryDNSTextControl->SetEnabled(enable);
fDomainTextControl->SetEnabled(enable);
}
@@ -360,6 +370,7 @@ EthernetSettingsView::_ApplyControlsToConfiguration()
fPrimaryDNSTextControl->Text()));
fCurrentSettings->NameServers().AddItem(new BString(
fSecondaryDNSTextControl->Text()));
fCurrentSettings->SetDomain(fDomainTextControl->Text());
fApplyButton->SetEnabled(false);
fRevertButton->SetEnabled(true);
@@ -404,6 +415,11 @@ EthernetSettingsView::_SaveDNSConfiguration()
<< "\n";
}
}
if (strlen(settings->Domain()) > 0) {
content << "domain\t"
<< settings->Domain()
<< "\n";
}
}
file.Write(content.String(), content.Length());
@@ -6,6 +6,7 @@
* Andre Alves Garzia, [email protected]
* Axel Dörfler
* Hugo Santos
* Vegard Wærp
*/
#ifndef ETHERNET_SETTINGS_VIEW_H
#define ETHERNET_SETTINGS_VIEW_H
@@ -65,6 +66,7 @@ private:
BTextControl* fPrimaryDNSTextControl;
BTextControl* fSecondaryDNSTextControl;
BTextControl* fDomainTextControl;
BStringView* fErrorMessage;
+2
View File
@@ -5,6 +5,7 @@
* Authors:
* Andre Alves Garzia, [email protected]
* Axel Dörfler, [email protected].
* Vegard Wærp, [email protected]
*/
@@ -159,5 +160,6 @@ Settings::ReadConfiguration()
fNameServers.AddItem(
new BString(inet_ntoa(state->nsaddr_list[i].sin_addr)));
}
fDomain = state->dnsrch[0];
}
}
+5 -1
View File
@@ -2,8 +2,9 @@
* Copyright 2004-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Authors:
* Andre Alves Garzia, [email protected]
* Vegard Wærp, [email protected]
*/
#ifndef SETTINGS_H
#define SETTINGS_H
@@ -21,6 +22,7 @@ public:
void SetIP(BString ip) { fIP = ip; }
void SetGateway(BString ip) { fGateway = ip; }
void SetNetmask(BString ip) { fNetmask = ip; }
void SetDomain(BString domain) { fDomain = domain; }
void SetAutoConfigure(bool autoConfigure)
{ fAuto = autoConfigure; }
@@ -28,6 +30,7 @@ public:
const char* Gateway() { return fGateway.String(); }
const char* Netmask() { return fNetmask.String(); }
const char* Name() { return fName.String(); }
const char* Domain() { return fDomain.String(); }
bool AutoConfigure() { return fAuto; }
BObjectList<BString>& NameServers() { return fNameServers; }
@@ -41,6 +44,7 @@ private:
BString fGateway;
BString fNetmask;
BString fName;
BString fDomain;
int fSocket;
bool fAuto;
BObjectList<BString> fNameServers;
+13
View File
@@ -4,6 +4,7 @@
*
* Authors:
* Axel Dörfler, [email protected]
* Vegard Wærp, [email protected]
*/
@@ -681,6 +682,18 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address)
memcpy(name, data, size);
name[size] = '\0';
syslog(LOG_INFO, "DHCP domain name: \"%s\"\n", name);
BPath path;
if (find_directory(B_COMMON_SETTINGS_DIRECTORY, &path) != B_OK)
break;
path.Append("network/resolv.conf");
FILE* file = fopen(path.Path(), "a");
if (file != NULL) {
fprintf(file, "domain %s\n", name);
fclose(file);
}
break;
}