diff options
author | Maciej <sppmacd@pm.me> | 2022-07-01 17:23:41 +0200 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-07-09 09:22:25 +0100 |
commit | 20430ffeae78a89ddf55bd45c50661b39754251a (patch) | |
tree | 0a287aa5138c5c1cf458ce9f8b7c527ec1330a9b /Userland/Utilities/route.cpp | |
parent | bea1668159c413a601fa5319e276ede16322e590 (diff) | |
download | serenity-20430ffeae78a89ddf55bd45c50661b39754251a.zip |
route: Support removing entries with unknown gateway
Diffstat (limited to 'Userland/Utilities/route.cpp')
-rw-r--r-- | Userland/Utilities/route.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Userland/Utilities/route.cpp b/Userland/Utilities/route.cpp index 2c382d6488..c4576a8b49 100644 --- a/Userland/Utilities/route.cpp +++ b/Userland/Utilities/route.cpp @@ -166,7 +166,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) } auto gateway = AK::IPv4Address::from_string(value_gateway_address); - if (!gateway.has_value()) { + if (action_add && !gateway.has_value()) { warnln("Invalid gateway IPv4 address: '{}'", value_gateway_address); return 1; } @@ -185,15 +185,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) rt.rt_dev = const_cast<char*>(value_interface.characters_without_null_termination()); rt.rt_gateway.sa_family = AF_INET; ((sockaddr_in&)rt.rt_dst).sin_addr.s_addr = destination.value().to_in_addr_t(); - ((sockaddr_in&)rt.rt_gateway).sin_addr.s_addr = gateway.value().to_in_addr_t(); + ((sockaddr_in&)rt.rt_gateway).sin_addr.s_addr = gateway.value_or(IPv4Address {}).to_in_addr_t(); ((sockaddr_in&)rt.rt_genmask).sin_addr.s_addr = genmask.value().to_in_addr_t(); rt.rt_flags = RTF_UP; if (!value_host_address.is_empty()) rt.rt_flags |= RTF_HOST; - if (gateway.has_value()) - rt.rt_flags |= RTF_GATEWAY; + rt.rt_flags |= RTF_GATEWAY; if (action_add) TRY(Core::System::ioctl(fd, SIOCADDRT, &rt)); |