mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
ifconfig: Stop supporting setting/displaying default gateway
The `route` command allows more sophiscated control over routing tables now, and supporting this in ifconfig is no longer meaningful.
This commit is contained in:
parent
bcf124c07d
commit
06c90b35ec
Notes:
sideshowbarker
2024-07-18 22:57:59 +09:00
Author: https://github.com/sppmacd Commit: https://github.com/SerenityOS/serenity/commit/06c90b35ec Pull-request: https://github.com/SerenityOS/serenity/pull/13857 Reviewed-by: https://github.com/brapru
2 changed files with 2 additions and 31 deletions
|
@ -5,7 +5,7 @@ ifconfig
|
|||
## Synopsis
|
||||
|
||||
```sh
|
||||
$ ifconfig [--ipv4 ip] [--adapter adapter] [--gateway gateway] [--mask mask]
|
||||
$ ifconfig [--ipv4 ip] [--adapter adapter] [--mask mask]
|
||||
```
|
||||
|
||||
## Description
|
||||
|
@ -16,7 +16,6 @@ Display or modify the configuration of each network interface.
|
|||
|
||||
* `-i ip`, `--ipv4 ip`: Set the IP address of the selected network
|
||||
* `-a adapter`, `--adapter adapter`: Select a specific network adapter to configure
|
||||
* `-g gateway`, `--gateway gateway`: Set the default gateway of the selected network
|
||||
* `-m mask`, `--mask mask`: Set the network mask of the selected network
|
||||
|
||||
<!-- Auto-generated through ArgsParser -->
|
||||
|
|
|
@ -27,18 +27,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
{
|
||||
char const* value_ipv4 = nullptr;
|
||||
char const* value_adapter = nullptr;
|
||||
char const* value_gateway = nullptr;
|
||||
char const* value_mask = nullptr;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.set_general_help("Display or modify the configuration of each network interface.");
|
||||
args_parser.add_option(value_ipv4, "Set the IP address of the selected network", "ipv4", 'i', "ip");
|
||||
args_parser.add_option(value_adapter, "Select a specific network adapter to configure", "adapter", 'a', "adapter");
|
||||
args_parser.add_option(value_gateway, "Set the default gateway of the selected network", "gateway", 'g', "gateway");
|
||||
args_parser.add_option(value_mask, "Set the network mask of the selected network", "mask", 'm', "mask");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
if (!value_ipv4 && !value_adapter && !value_gateway && !value_mask) {
|
||||
if (!value_ipv4 && !value_adapter && !value_mask) {
|
||||
auto file = TRY(Core::File::open("/proc/net/adapters", Core::OpenMode::ReadOnly));
|
||||
auto json = TRY(JsonValue::from_string(file->read_all()));
|
||||
|
||||
|
@ -49,7 +47,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto class_name = if_object.get("class_name").to_string();
|
||||
auto mac_address = if_object.get("mac_address").to_string();
|
||||
auto ipv4_address = if_object.get("ipv4_address").to_string();
|
||||
auto gateway = if_object.get("ipv4_gateway").to_string();
|
||||
auto netmask = if_object.get("ipv4_netmask").to_string();
|
||||
auto packets_in = if_object.get("packets_in").to_u32();
|
||||
auto bytes_in = if_object.get("bytes_in").to_u32();
|
||||
|
@ -61,7 +58,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
outln("\tmac: {}", mac_address);
|
||||
outln("\tipv4: {}", ipv4_address);
|
||||
outln("\tnetmask: {}", netmask);
|
||||
outln("\tgateway: {}", gateway);
|
||||
outln("\tclass: {}", class_name);
|
||||
outln("\tRX: {} packets {} bytes ({})", packets_in, bytes_in, human_readable_size(bytes_in));
|
||||
outln("\tTX: {} packets {} bytes ({})", packets_out, bytes_out, human_readable_size(bytes_out));
|
||||
|
@ -140,30 +136,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (value_gateway) {
|
||||
auto address = IPv4Address::from_string(value_gateway);
|
||||
|
||||
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||
if (fd < 0) {
|
||||
perror("socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct rtentry rt;
|
||||
memset(&rt, 0, sizeof(rt));
|
||||
|
||||
rt.rt_dev = const_cast<char*>(ifname.characters());
|
||||
rt.rt_gateway.sa_family = AF_INET;
|
||||
((sockaddr_in&)rt.rt_gateway).sin_addr.s_addr = address.value().to_in_addr_t();
|
||||
rt.rt_flags = RTF_UP | RTF_GATEWAY;
|
||||
|
||||
int rc = ioctl(fd, SIOCADDRT, &rt);
|
||||
if (rc < 0) {
|
||||
perror("ioctl(SIOCADDRT)");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue