1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 10:05:07 +00:00
serenity/Userland/Services/DHCPClient/DHCPv4.cpp
2022-04-01 21:24:45 +01:00

36 lines
1 KiB
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "DHCPv4.h"
#include <AK/Debug.h>
ParsedDHCPv4Options DHCPv4Packet::parse_options() const
{
ParsedDHCPv4Options options;
for (size_t index = 4; index < DHCPV4_OPTION_FIELD_MAX_LENGTH; ++index) {
auto opt_name = *(DHCPOption const*)&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) {
dbgln("Bogus option length {} assuming forgotten END", length);
break;
}
dbgln_if(DHCPV4_DEBUG, "DHCP Option {} with length {}", (u8)opt_name, length);
++index;
options.options.set(opt_name, { length, &m_options[index] });
index += length - 1;
break;
}
}
escape:;
return options;
}