summaryrefslogtreecommitdiff
path: root/Userland/Utilities/route.cpp
diff options
context:
space:
mode:
authorbrapru <brapru@pm.me>2022-05-09 07:25:31 -0400
committerAndreas Kling <kling@serenityos.org>2022-05-26 16:33:10 +0200
commit1297f81ddfee6fc7d55e64c77fa167ac5425b4b2 (patch)
tree2ad9ede2577bc3beab35b7436251a1625d0716d9 /Userland/Utilities/route.cpp
parent7a4e41f8f8ab49507f549412ffc8d4042e511918 (diff)
downloadserenity-1297f81ddfee6fc7d55e64c77fa167ac5425b4b2.zip
route: Add the flags column
Diffstat (limited to 'Userland/Utilities/route.cpp')
-rw-r--r--Userland/Utilities/route.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/Userland/Utilities/route.cpp b/Userland/Utilities/route.cpp
index 881268f513..2c382d6488 100644
--- a/Userland/Utilities/route.cpp
+++ b/Userland/Utilities/route.cpp
@@ -62,6 +62,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
int destination_column = -1;
int gateway_column = -1;
int genmask_column = -1;
+ int flags_column = -1;
int interface_column = -1;
auto add_column = [&](auto title, auto alignment, auto width) {
@@ -72,6 +73,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
destination_column = add_column("Destination", Alignment::Left, 15);
gateway_column = add_column("Gateway", Alignment::Left, 15);
genmask_column = add_column("Genmask", Alignment::Left, 15);
+ flags_column = add_column("Flags", Alignment::Left, 5);
interface_column = add_column("Interface", Alignment::Left, 9);
auto print_column = [](auto& column, auto& string) {
@@ -109,6 +111,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto gateway = if_object.get("gateway").to_string();
auto genmask = if_object.get("genmask").to_string();
auto interface = if_object.get("interface").to_string();
+ auto flags = if_object.get("flags").to_u32();
+
+ StringBuilder flags_builder;
+ if (flags & RTF_UP)
+ flags_builder.append("U");
+ if (flags & RTF_GATEWAY)
+ flags_builder.append("G");
+ if (flags & RTF_HOST)
+ flags_builder.append("H");
if (destination_column != -1)
columns[destination_column].buffer = destination;
@@ -116,6 +127,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
columns[gateway_column].buffer = gateway;
if (genmask_column != -1)
columns[genmask_column].buffer = genmask;
+ if (flags_column != -1)
+ columns[flags_column].buffer = flags_builder.string_view();
if (interface_column != -1)
columns[interface_column].buffer = interface;
@@ -174,7 +187,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
((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_genmask).sin_addr.s_addr = genmask.value().to_in_addr_t();
- rt.rt_flags = RTF_UP | RTF_GATEWAY;
+ 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;
if (action_add)
TRY(Core::System::ioctl(fd, SIOCADDRT, &rt));