DHCPClient: Set Host Name option

This makes bare metal serenity systems reachable by their hostname
on my local network, which uses a FRITZ!Box as the router, DNS server,
and DHCP server. It appears to use this DHCP option to add DNS records
for "$hostname" and "$hostname.fritz.box".
This commit is contained in:
Sönke Holz authored and Nico Weber committed 2026-08-16 16:27:59 -04:00
1 parent 3f28a3d1db
commit 7c50847a92
1 file changed
+5
@@ -15,6 +15,7 @@
#include <AK/ScopeGuard.h>
#include <AK/Try.h>
#include <LibCore/File.h>
#include <LibCore/System.h>
#include <LibCore/Timer.h>
#include <stdio.h>
@@ -388,6 +389,10 @@ void DHCPv4Client::dhcp_request(DHCPv4Transaction& transaction, DHCPv4Packet con
if (maybe_dhcp_server_ip.has_value())
builder.add_option(DHCPOption::ServerIdentifier, sizeof(IPv4Address), &maybe_dhcp_server_ip.value());
auto hostname = Core::System::gethostname();
if (!hostname.is_error())
builder.add_option(DHCPOption::HostName, hostname.value().length(), hostname.value().characters());
AK::Array<DHCPOption, 2> parameter_request_list = {
DHCPOption::SubnetMask,
DHCPOption::Router,