mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:37:35 +00:00
DHCPClient: Don't reject packets smaller than the max size
It's acceptable to have less padding in a packet, the only requirement is to have a single byte of 'END' in the DHCP fields.
This commit is contained in:
parent
c0703f48fe
commit
3440dbb1fc
2 changed files with 8 additions and 4 deletions
|
@ -53,7 +53,9 @@ static void send(const InterfaceDescriptor& iface, const DHCPv4Packet& packet, C
|
|||
dst.sin_addr.s_addr = IPv4Address { 255, 255, 255, 255 }.to_u32();
|
||||
memset(&dst.sin_zero, 0, sizeof(dst.sin_zero));
|
||||
|
||||
dbgln_if(DHCPV4CLIENT_DEBUG, "sendto({} bound to {}, ..., {} at {}) = ...?", fd, iface.m_ifname, dst.sin_addr.s_addr, dst.sin_port);
|
||||
auto rc = sendto(fd, &packet, sizeof(packet), 0, (sockaddr*)&dst, sizeof(dst));
|
||||
dbgln_if(DHCPV4CLIENT_DEBUG, "sendto({}) = {}", fd, rc);
|
||||
if (rc < 0) {
|
||||
dbgln("sendto failed with {}", strerror(errno));
|
||||
// FIXME: what do we do here?
|
||||
|
@ -113,8 +115,8 @@ DHCPv4Client::DHCPv4Client(Vector<InterfaceDescriptor> ifnames)
|
|||
m_server->on_ready_to_receive = [this] {
|
||||
auto buffer = m_server->receive(sizeof(DHCPv4Packet));
|
||||
dbgln("Received {} bytes", buffer.size());
|
||||
if (buffer.size() != sizeof(DHCPv4Packet)) {
|
||||
dbgln("we expected {} bytes, this is a bad packet", sizeof(DHCPv4Packet));
|
||||
if (buffer.size() < sizeof(DHCPv4Packet) - DHCPV4_OPTION_FIELD_MAX_LENGTH + 1 || buffer.size() > sizeof(DHCPv4Packet)) {
|
||||
dbgln("we expected {}-{} bytes, this is a bad packet", sizeof(DHCPv4Packet) - DHCPV4_OPTION_FIELD_MAX_LENGTH + 1, sizeof(DHCPv4Packet));
|
||||
return;
|
||||
}
|
||||
auto& packet = *(DHCPv4Packet*)buffer.data();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include "DHCPv4Client.h"
|
||||
#include <AK/Debug.h>
|
||||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/String.h>
|
||||
|
@ -69,7 +70,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
|
||||
auto file = Core::File::construct("/proc/net/adapters");
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
warnln("Error: {}", file->error_string());
|
||||
dbgln("Error: {}", file->error_string());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -77,7 +78,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
auto json = JsonValue::from_string(file_contents);
|
||||
|
||||
if (!json.has_value() || !json.value().is_array()) {
|
||||
warnln("Error: No network adapters available");
|
||||
dbgln("Error: No network adapters available");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -90,6 +91,7 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
|||
|
||||
auto name = if_object.get("name").to_string();
|
||||
auto mac = if_object.get("mac_address").to_string();
|
||||
dbgln_if(DHCPV4_DEBUG, "Found adapter '{}' with mac {}", name, mac);
|
||||
ifnames.append({ name, mac_from_string(mac) });
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue