* Use SetToWildcard() to init the local address.
* Implement OPTION_OVERLOAD support in dhcp_message::NextOption(). Untested. * Comment out an ASSERT which don't compile in DEBUG mode (and make no sense for me, BTW) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39607 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -160,7 +160,7 @@ static const uint8 kRequestParameters[] = {
|
|||||||
|
|
||||||
dhcp_message::dhcp_message(message_type type)
|
dhcp_message::dhcp_message(message_type type)
|
||||||
{
|
{
|
||||||
ASSERT(this == offsetof(this, opcode));
|
// ASSERT(this == offsetof(this, opcode));
|
||||||
memset(this, 0, sizeof(*this));
|
memset(this, 0, sizeof(*this));
|
||||||
options_magic = htonl(OPTION_MAGIC);
|
options_magic = htonl(OPTION_MAGIC);
|
||||||
|
|
||||||
@@ -180,10 +180,10 @@ bool
|
|||||||
dhcp_message::NextOption(dhcp_option_cookie& cookie,
|
dhcp_message::NextOption(dhcp_option_cookie& cookie,
|
||||||
message_option& option, const uint8*& data, size_t& size) const
|
message_option& option, const uint8*& data, size_t& size) const
|
||||||
{
|
{
|
||||||
if (cookie.state == 0) {
|
if (!HasOptions())
|
||||||
if (!HasOptions())
|
return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
|
if (cookie.state == 0) {
|
||||||
cookie.state++;
|
cookie.state++;
|
||||||
cookie.next = options;
|
cookie.next = options;
|
||||||
}
|
}
|
||||||
@@ -192,32 +192,58 @@ dhcp_message::NextOption(dhcp_option_cookie& cookie,
|
|||||||
|
|
||||||
switch (cookie.state) {
|
switch (cookie.state) {
|
||||||
case 1:
|
case 1:
|
||||||
// options from "options"
|
// iterate options from "options"
|
||||||
bytesLeft = sizeof(options) + cookie.next - options;
|
bytesLeft = sizeof(options) - (cookie.next - options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// options from "file"
|
// options from "file"
|
||||||
bytesLeft = sizeof(options) + cookie.next - options;
|
bytesLeft = sizeof(file) - (cookie.next - file);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
// options from "server_name"
|
// options from "server_name"
|
||||||
bytesLeft = sizeof(options) + cookie.next - options;
|
bytesLeft = sizeof(server_name) - (cookie.next - server_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (bytesLeft == 0) {
|
if (bytesLeft == 0) {
|
||||||
// TODO: suppport OPTION_OVERLOAD!
|
cookie.state++;
|
||||||
cookie.state = 4;
|
|
||||||
return false;
|
// handle option(s) overload in file and/or server_name fields.
|
||||||
|
switch (cookie.state) {
|
||||||
|
case 2:
|
||||||
|
// options from "file"
|
||||||
|
if (cookie.file_has_options) {
|
||||||
|
bytesLeft = sizeof(file);
|
||||||
|
cookie.next = file;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
// options from "server_name"
|
||||||
|
if (cookie.server_name_has_options) {
|
||||||
|
bytesLeft = sizeof(server_name);
|
||||||
|
cookie.next = server_name;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
// no more options
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytesLeft == 0) {
|
||||||
|
// no options for this state, try next one
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
option = (message_option)cookie.next[0];
|
option = (message_option)cookie.next[0];
|
||||||
if (option == OPTION_END) {
|
if (option == OPTION_END) {
|
||||||
cookie.state = 4;
|
bytesLeft = 0;
|
||||||
return false;
|
continue;
|
||||||
} else if (option == OPTION_PAD) {
|
} else if (option == OPTION_PAD) {
|
||||||
bytesLeft--;
|
bytesLeft--;
|
||||||
cookie.next++;
|
cookie.next++;
|
||||||
@@ -227,6 +253,7 @@ dhcp_message::NextOption(dhcp_option_cookie& cookie,
|
|||||||
size = cookie.next[1];
|
size = cookie.next[1];
|
||||||
data = &cookie.next[2];
|
data = &cookie.next[2];
|
||||||
cookie.next += 2 + size;
|
cookie.next += 2 + size;
|
||||||
|
bytesLeft -= 2 + size;
|
||||||
|
|
||||||
if (option == OPTION_OVERLOAD) {
|
if (option == OPTION_OVERLOAD) {
|
||||||
cookie.file_has_options = data[0] & 1;
|
cookie.file_has_options = data[0] & 1;
|
||||||
@@ -425,7 +452,8 @@ DHCPClient::_Negotiate(dhcp_state state)
|
|||||||
if (socket < 0)
|
if (socket < 0)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
BNetworkAddress local(AF_INET, NULL, DHCP_CLIENT_PORT);
|
BNetworkAddress local;
|
||||||
|
local.SetToWildcard(AF_INET, DHCP_CLIENT_PORT);
|
||||||
|
|
||||||
// Enable reusing the port . This is needed in case there is more
|
// Enable reusing the port . This is needed in case there is more
|
||||||
// than 1 interface that needs to be configured. Note that the only reason
|
// than 1 interface that needs to be configured. Note that the only reason
|
||||||
|
|||||||
Reference in New Issue
Block a user