main.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "DHCPv4Client.h"
  7. #include <AK/Debug.h>
  8. #include <AK/JsonArray.h>
  9. #include <AK/JsonObject.h>
  10. #include <AK/String.h>
  11. #include <AK/StringUtils.h>
  12. #include <AK/Types.h>
  13. #include <LibCore/EventLoop.h>
  14. #include <LibCore/File.h>
  15. #include <LibCore/LocalServer.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <unistd.h>
  19. int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
  20. {
  21. if (pledge("stdio unix inet cpath rpath", nullptr) < 0) {
  22. perror("pledge");
  23. return 1;
  24. }
  25. Core::EventLoop event_loop;
  26. if (unveil("/proc/net/", "r") < 0) {
  27. perror("unveil");
  28. return 1;
  29. }
  30. unveil(nullptr, nullptr);
  31. auto ifs_result = DHCPv4Client::get_discoverable_interfaces();
  32. if (ifs_result.is_error()) {
  33. warnln("Error: {}", ifs_result.error());
  34. return 1;
  35. }
  36. auto ifs = ifs_result.release_value();
  37. auto client = DHCPv4Client::construct(move(ifs.ready), move(ifs.not_ready));
  38. if (pledge("stdio inet cpath rpath", nullptr) < 0) {
  39. perror("pledge");
  40. return 1;
  41. }
  42. return event_loop.exec();
  43. }