arp.cpp 1018 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Assertions.h>
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/JsonObject.h>
  9. #include <AK/String.h>
  10. #include <LibCore/File.h>
  11. #include <stdio.h>
  12. int main()
  13. {
  14. auto file = Core::File::construct("/proc/net/arp");
  15. if (!file->open(Core::OpenMode::ReadOnly)) {
  16. fprintf(stderr, "Error: %s\n", file->error_string());
  17. return 1;
  18. }
  19. printf("Address HWaddress\n");
  20. auto file_contents = file->read_all();
  21. auto json = JsonValue::from_string(file_contents);
  22. VERIFY(json.has_value());
  23. json.value().as_array().for_each([](auto& value) {
  24. auto if_object = value.as_object();
  25. auto ip_address = if_object.get("ip_address").to_string();
  26. auto mac_address = if_object.get("mac_address").to_string();
  27. printf("%-15s ", ip_address.characters());
  28. printf("%-17s ", mac_address.characters());
  29. printf("\n");
  30. });
  31. return 0;
  32. }