Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 1 | From 658e0a69a353e2559ab04c3caa7ea1eaf0ef6dda Mon Sep 17 00:00:00 2001 |
| 2 | From: Tomas Pecka <peckato1@users.noreply.github.com> |
| 3 | Date: Wed, 15 Sep 2021 14:30:19 +0200 |
| 4 | Subject: [PATCH 8/9] networkctl: allow format LLDP capabilities string without |
| 5 | dots |
| 6 | |
| 7 | Allows formatting the LLDP capabilities string without the dots |
| 8 | representing "not enabled" (just omit them). |
| 9 | --- |
| 10 | src/network/networkctl.c | 15 +++++++++------ |
| 11 | 1 file changed, 9 insertions(+), 6 deletions(-) |
| 12 | |
| 13 | diff --git a/src/network/networkctl.c b/src/network/networkctl.c |
| 14 | index f98779da7e..89abaf26da 100644 |
| 15 | --- a/src/network/networkctl.c |
| 16 | +++ b/src/network/networkctl.c |
| 17 | @@ -2433,21 +2433,24 @@ static int link_status(int argc, char *argv[], void *userdata) { |
| 18 | return 0; |
| 19 | } |
| 20 | |
| 21 | -static char *lldp_capabilities_to_string(uint16_t x) { |
| 22 | +static char *lldp_capabilities_to_string(uint16_t x, bool dots) { |
| 23 | static const char characters[] = { |
| 24 | 'o', 'p', 'b', 'w', 'r', 't', 'd', 'a', 'c', 's', 'm', |
| 25 | }; |
| 26 | char *ret; |
| 27 | - unsigned i; |
| 28 | + unsigned i, j; |
| 29 | |
| 30 | ret = new(char, ELEMENTSOF(characters) + 1); |
| 31 | if (!ret) |
| 32 | return NULL; |
| 33 | |
| 34 | - for (i = 0; i < ELEMENTSOF(characters); i++) |
| 35 | - ret[i] = (x & (1U << i)) ? characters[i] : '.'; |
| 36 | + for (i = 0, j = 0; i < ELEMENTSOF(characters); i++) |
| 37 | + if (x & (1U << i)) |
| 38 | + ret[j++] = characters[i]; |
| 39 | + else if (dots) |
| 40 | + ret[j++] = '.'; |
| 41 | |
| 42 | - ret[i] = 0; |
| 43 | + ret[j] = 0; |
| 44 | return ret; |
| 45 | } |
| 46 | |
| 47 | @@ -2534,7 +2537,7 @@ static int lldp_neighbours_varlink_reply(Varlink *link, JsonVariant *parameters, |
| 48 | return r; |
| 49 | |
| 50 | if (udata->table) { |
| 51 | - capabilities = lldp_capabilities_to_string(entry.capabilities); |
| 52 | + capabilities = lldp_capabilities_to_string(entry.capabilities, true); |
| 53 | |
| 54 | r = table_add_many(udata->table, |
| 55 | TABLE_STRING, udata->link_name, |
| 56 | -- |
| 57 | 2.33.0 |
| 58 | |