diff options
author | brapru <brapru@pm.me> | 2022-04-05 06:16:28 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-05 12:43:18 +0200 |
commit | 3dbb4bc3a617e3ca421a35c6196ad5902bb357d1 (patch) | |
tree | 4dc9ea3e0586c3e54fab2dd7e7fc5cbf595dd104 | |
parent | 26b8155530409651317a33bcb43d75b91e8f0d5d (diff) | |
download | serenity-3dbb4bc3a617e3ca421a35c6196ad5902bb357d1.zip |
Utilities: Update arp to use newer APIs
Updates the arp command to use Core::System for the socket and
ioctl calls.
Updates command line arguments to StringView.
-rw-r--r-- | Userland/Utilities/arp.cpp | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/Userland/Utilities/arp.cpp b/Userland/Utilities/arp.cpp index b8cd9510cc..e4d913fad1 100644 --- a/Userland/Utilities/arp.cpp +++ b/Userland/Utilities/arp.cpp @@ -31,8 +31,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) static bool flag_set; static bool flag_delete; - char const* value_ipv4_address = nullptr; - char const* value_hw_address = nullptr; + StringView value_ipv4_address; + StringView value_hw_address; Core::ArgsParser args_parser; args_parser.set_general_help("Display or modify the system ARP cache"); @@ -121,7 +121,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } if (flag_set || flag_delete) { - if (!value_ipv4_address || !value_hw_address) { + if (value_ipv4_address.is_empty() || value_hw_address.is_empty()) { warnln("No protocol address or hardware address specified."); return 1; } @@ -138,11 +138,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) return 1; } - int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); - if (fd < 0) { - perror("socket"); - return 1; - } + int fd = TRY(Core::System::socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)); struct arpreq arp_req; memset(&arp_req, 0, sizeof(arp_req)); @@ -152,19 +148,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) *(MACAddress*)&arp_req.arp_ha.sa_data[0] = hw_address.value(); - int rc = 0; if (flag_set) - rc = ioctl(fd, SIOCSARP, &arp_req); - if (flag_delete) { - int rc2 = ioctl(fd, SIOCDARP, &arp_req); - if (!rc2) - rc = rc2; - } - - if (rc < 0) { - perror("ioctl"); - return 1; - } + TRY(Core::System::ioctl(fd, SIOCSARP, &arp_req)); + if (flag_delete) + TRY(Core::System::ioctl(fd, SIOCDARP, &arp_req)); } return 0; |