From a552ec1396053105da3b962eb0971b0e8e922612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 12 Dec 2006 16:11:16 +0000 Subject: [PATCH] * If DHCP reports DNS addresses, we'll now rewrite /etc/resolv.conf for now. * minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19477 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/net/DHCPClient.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/servers/net/DHCPClient.cpp b/src/servers/net/DHCPClient.cpp index 060103c94d..2d6c259c97 100644 --- a/src/servers/net/DHCPClient.cpp +++ b/src/servers/net/DHCPClient.cpp @@ -211,7 +211,7 @@ dhcp_message::Type() const { dhcp_option_cookie cookie; message_option option; - const uint8 *data; + const uint8* data; size_t size; while (NextOption(cookie, option, data, size)) { // iterate through all options @@ -228,7 +228,7 @@ dhcp_message::LastOption() const { dhcp_option_cookie cookie; message_option option; - const uint8 *data; + const uint8* data; size_t size; while (NextOption(cookie, option, data, size)) { // iterate through all options @@ -444,7 +444,7 @@ DHCPClient::DHCPClient(BMessenger target, const char* device) if (state != REQUESTING) continue; - // try again + // try again (maybe we should prefer other servers if this happens more than once) fStatus = _SendMessage(socket, discover, broadcast); if (fStatus == B_OK) state = INIT; @@ -480,7 +480,7 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address) { dhcp_option_cookie cookie; message_option option; - const uint8 *data; + const uint8* data; size_t size; while (message.NextOption(cookie, option, data, size)) { // iterate through all options @@ -492,11 +492,17 @@ DHCPClient::_ParseOptions(dhcp_message& message, BMessage& address) address.AddString("mask", _ToString(data)); break; case OPTION_DOMAIN_NAME_SERVER: - // TODO: for now, write it out to /etc/resolv.conf + { + // TODO: for now, we write it just out to /etc/resolv.conf + FILE* file = fopen("/etc/resolv.conf", "w"); for (uint32 i = 0; i < size / 4; i++) { printf("DNS: %s\n", _ToString(&data[i*4]).String()); + if (file != NULL) + fprintf(file, "nameserver %s\n", _ToString(&data[i*4]).String()); } + fclose(file); break; + } case OPTION_SERVER_ADDRESS: fServer.sin_addr.s_addr = *(in_addr_t*)data; break;