| From a36487ec3e3a5d1bbfb11747bf48354c962a097a Mon Sep 17 00:00:00 2001 |
| From: Tomas Pecka <peckato1@users.noreply.github.com> |
| Date: Wed, 15 Sep 2021 14:30:19 +0200 |
| Subject: [PATCH 6/7] networkctl: allow format LLDP capabilities string without |
| dots |
| |
| Allows formatting the LLDP capabilities string without the dots |
| representing "not enabled" (just omit them). |
| --- |
| src/network/networkctl.c | 15 +++++++++------ |
| 1 file changed, 9 insertions(+), 6 deletions(-) |
| |
| diff --git a/src/network/networkctl.c b/src/network/networkctl.c |
| index bab6cf5433..04a89e015f 100644 |
| --- a/src/network/networkctl.c |
| +++ b/src/network/networkctl.c |
| @@ -2391,21 +2391,24 @@ static int link_status(int argc, char *argv[], void *userdata) { |
| return 0; |
| } |
| |
| -static char *lldp_capabilities_to_string(uint16_t x) { |
| +static char *lldp_capabilities_to_string(uint16_t x, bool dots) { |
| static const char characters[] = { |
| 'o', 'p', 'b', 'w', 'r', 't', 'd', 'a', 'c', 's', 'm', |
| }; |
| char *ret; |
| - unsigned i; |
| + unsigned i, j; |
| |
| ret = new(char, ELEMENTSOF(characters) + 1); |
| if (!ret) |
| return NULL; |
| |
| - for (i = 0; i < ELEMENTSOF(characters); i++) |
| - ret[i] = (x & (1U << i)) ? characters[i] : '.'; |
| + for (i = 0, j = 0; i < ELEMENTSOF(characters); i++) |
| + if (x & (1U << i)) |
| + ret[j++] = characters[i]; |
| + else if (dots) |
| + ret[j++] = '.'; |
| |
| - ret[i] = 0; |
| + ret[j] = 0; |
| return ret; |
| } |
| |
| @@ -2497,7 +2500,7 @@ static int lldp_neighbors_varlink_reply(Varlink *link, JsonVariant *parameters, |
| return r; |
| |
| if (udata->table) { |
| - capabilities = lldp_capabilities_to_string(entry.capabilities); |
| + capabilities = lldp_capabilities_to_string(entry.capabilities, true); |
| |
| r = table_add_many(udata->table, |
| TABLE_STRING, udata->link_name, |
| -- |
| 2.41.0 |
| |