diff options
author | Chocobo1 <Chocobo1@users.noreply.github.com> | 2015-05-31 20:56:25 +0800 |
---|---|---|
committer | Chocobo1 <Chocobo1@users.noreply.github.com> | 2015-05-31 21:27:52 +0800 |
commit | 51a24c315b62acce4f2b04a410b2216742aa8b39 (patch) | |
tree | 1578f1f11f746baebc339837b58488e0d3e954b7 | |
parent | 5cecc86856f717711e05696d6202180bfe335ac8 (diff) |
Fix wrong unit displayed when using "--use-bit" option
-rw-r--r-- | src/in_netlink.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/in_netlink.c b/src/in_netlink.c index 8dd74fe..d71ee9a 100644 --- a/src/in_netlink.c +++ b/src/in_netlink.c @@ -774,6 +774,17 @@ static void netlink_shutdown(void) nl_socket_free(sock); } +static void netlink_use_bit(struct attr_map *map, const int size) +{ + if(cfg_getbool(cfg, "use_bit")) { + for(int i = 0; i < size; ++i) { + if(!strcmp(map[i].description, "Bytes")) { + map[i].description = "Bits"; + } + } + } +} + static int netlink_do_init(void) { int err; @@ -798,6 +809,8 @@ static int netlink_do_init(void) goto disable; } + netlink_use_bit(link_attrs, ARRAY_SIZE(link_attrs)); + netlink_use_bit(tc_attrs, ARRAY_SIZE(tc_attrs)); if (attr_map_load(link_attrs, ARRAY_SIZE(link_attrs)) || attr_map_load(tc_attrs, ARRAY_SIZE(tc_attrs))) BUG(); @@ -819,17 +832,17 @@ static int netlink_probe(void) if (!(sock = nl_socket_alloc())) return 0; - + if (nl_connect(sock, NETLINK_ROUTE) < 0) return 0; - + if (rtnl_link_alloc_cache(sock, AF_UNSPEC, &lc) == 0) { nl_cache_free(lc); ret = 1; } nl_socket_free(sock); - + return ret; } |