On 5/15/18 7:54 AM, Jon Maloy wrote:
> We make it easier for users to correlate between 128-bit node
> identities and 32-bit node hash number by extending the 'node list'
> command to also show the hash number.
> 
> We also improve the 'nametable show' command to show the node identity
> instead of the node hash number. Since the former potentially is much
> longer than the latter, we make room for it by eliminating the (to the
> user) irrelevant publication key. We also reorder some of the columns so
> that the node id comes last, since this looks nicer and is more logical.
> 
> ---
> v2: Fixed compiler warning as per comment from David Ahern
> 
> Signed-off-by: Jon Maloy <jon.ma...@ericsson.com>
> ---
>  tipc/misc.c      | 18 ++++++++++++++++++
>  tipc/misc.h      |  1 +
>  tipc/nametable.c | 18 ++++++++++--------
>  tipc/node.c      | 19 ++++++++-----------
>  tipc/peer.c      |  4 ++++
>  5 files changed, 41 insertions(+), 19 deletions(-)
> 
> diff --git a/tipc/misc.c b/tipc/misc.c
> index 16849f1..e8b726f 100644
> --- a/tipc/misc.c
> +++ b/tipc/misc.c
> @@ -13,6 +13,9 @@
>  #include <stdint.h>
>  #include <linux/tipc.h>
>  #include <string.h>
> +#include <sys/ioctl.h>
> +#include <sys/socket.h>
> +#include <errno.h>
>  #include "misc.h"
>  
>  #define IN_RANGE(val, low, high) ((val) <= (high) && (val) >= (low))
> @@ -109,3 +112,18 @@ void nodeid2str(uint8_t *id, char *str)
>       for (i = 31; str[i] == '0'; i--)
>               str[i] = 0;
>  }
> +
> +void hash2nodestr(uint32_t hash, char *str)
> +{
> +     struct tipc_sioc_nodeid_req nr = {};
> +     int sd;
> +
> +     sd = socket(AF_TIPC, SOCK_RDM, 0);
> +     if (sd < 0) {
> +             fprintf(stderr, "opening TIPC socket: %s\n", strerror(errno));
> +             return;
> +     }
> +     nr.peer = hash;
> +     if (!ioctl(sd, SIOCGETNODEID, &nr))
> +             nodeid2str((uint8_t *)nr.node_id, str);
> +}

you are leaking sd

Reply via email to