1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 14:35:07 +00:00
serenity/Userland/Services/DHCPClient/main.cpp
Maciej e14d4482a1 DHCPClient: Don't discover interfaces other than given by default
Now, the caller needs to give interface names in command-line arguments.
The DHCPClient will perform DHCP discovery only on these adapters. The
service now immediately closes when no interfaces were given.

We don't check if interface has already IP address assigned; we just
reset it to zero so that DHCP resolution will not fail.
2022-05-26 21:47:27 +01:00

31 lines
827 B
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "DHCPv4Client.h"
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments args)
{
Vector<String> interfaces;
Core::ArgsParser parser;
parser.add_positional_argument(interfaces, "Interfaces to run DHCP server on", "interfaces");
parser.parse(args);
TRY(Core::System::pledge("stdio unix inet cpath rpath"));
Core::EventLoop event_loop;
TRY(Core::System::unveil("/proc/net/", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
auto client = TRY(DHCPv4Client::try_create(interfaces));
TRY(Core::System::pledge("stdio inet cpath rpath"));
return event_loop.exec();
}