1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

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.
This commit is contained in:
Maciej 2022-05-07 14:59:34 +02:00 committed by Linus Groh
parent 01c7158ffe
commit e14d4482a1
3 changed files with 22 additions and 5 deletions

View file

@ -5,19 +5,26 @@
*/
#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)
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());
auto client = TRY(DHCPv4Client::try_create(interfaces));
TRY(Core::System::pledge("stdio inet cpath rpath"));
return event_loop.exec();