2020-04-04 08:19:30 -03:00
|
|
|
/*
|
2021-04-28 17:46:44 -03:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2020-04-04 08:19:30 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-04 08:19:30 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "DHCPv4.h"
|
2021-01-17 14:17:00 -03:00
|
|
|
#include <AK/Debug.h>
|
2020-04-04 08:19:30 -03:00
|
|
|
|
|
|
|
|
ParsedDHCPv4Options DHCPv4Packet::parse_options() const
|
|
|
|
|
{
|
|
|
|
|
ParsedDHCPv4Options options;
|
|
|
|
|
for (size_t index = 4; index < DHCPV4_OPTION_FIELD_MAX_LENGTH; ++index) {
|
|
|
|
|
auto opt_name = *(const DHCPOption*)&m_options[index];
|
|
|
|
|
switch (opt_name) {
|
|
|
|
|
case DHCPOption::Pad:
|
|
|
|
|
continue;
|
|
|
|
|
case DHCPOption::End:
|
|
|
|
|
goto escape;
|
|
|
|
|
default:
|
|
|
|
|
++index;
|
|
|
|
|
auto length = m_options[index];
|
|
|
|
|
if ((size_t)length > DHCPV4_OPTION_FIELD_MAX_LENGTH - index) {
|
2021-01-17 14:17:00 -03:00
|
|
|
dbgln("Bogus option length {} assuming forgotten END", length);
|
2020-04-04 08:19:30 -03:00
|
|
|
break;
|
|
|
|
|
}
|
2021-02-07 09:03:24 -03:00
|
|
|
dbgln_if(DHCPV4_DEBUG, "DHCP Option {} with length {}", (u8)opt_name, length);
|
2020-04-04 08:19:30 -03:00
|
|
|
++index;
|
|
|
|
|
options.options.set(opt_name, { length, &m_options[index] });
|
|
|
|
|
index += length - 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
escape:;
|
|
|
|
|
return options;
|
|
|
|
|
}
|