diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-08-12 16:19:37 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-12 16:19:37 +0200 |
commit | f7d68aa8c9430dfddee5f913f93b405a5d75723a (patch) | |
tree | 6b0ba6dbf32401fbca5b67dfa4cb9abd0cf53b73 /src/network | |
parent | 18af33753abc822ddf61aa37ff49368b7006fa79 (diff) |
networkctl: make networkctl status without link name show all local IP addresses
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkctl.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 397a0d31d2..47e918d402 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -396,14 +396,40 @@ static int link_status(char **args, unsigned n) { char **name; int r; + r = sd_rtnl_open(&rtnl, 0); + if (r < 0) { + log_error("Failed to connect to netlink: %s", strerror(-r)); + return r; + } + + udev = udev_new(); + if (!udev) { + log_error("Failed to connect to udev: %m"); + return -errno; + } + if (n <= 1 && !arg_all) { _cleanup_free_ char *operational_state = NULL; _cleanup_strv_free_ char **dns = NULL, **ntp = NULL; + _cleanup_free_ struct local_address *addresses = NULL; + int i, c; sd_network_get_operational_state(&operational_state); if (operational_state) printf(" State: %s\n", operational_state); + c = local_addresses(rtnl, 0, &addresses); + for (i = 0; i < c; i++) { + _cleanup_free_ char *pretty = NULL; + + r = in_addr_to_string(addresses[i].family, &addresses[i].address, &pretty); + if (r < 0) + return log_oom(); + + printf("%13s %s\n", + i > 0 ? "" : "Address:", pretty); + } + sd_network_get_dns(&dns); if (!strv_isempty(dns)) dump_list(" DNS: ", dns); @@ -417,18 +443,6 @@ static int link_status(char **args, unsigned n) { pager_open_if_enabled(); - r = sd_rtnl_open(&rtnl, 0); - if (r < 0) { - log_error("Failed to connect to netlink: %s", strerror(-r)); - return r; - } - - udev = udev_new(); - if (!udev) { - log_error("Failed to connect to udev: %m"); - return -errno; - } - if (arg_all) { _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL, *reply = NULL; _cleanup_free_ LinkInfo *links = NULL; |