]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tipc/misc.c
ll_map: Add function to remove link cache entry by index
[mirror_iproute2.git] / tipc / misc.c
index 16849f18cd5cbe89a97d149e9256e0ca2a2500ba..e4b1cd0cc6e5b30e6f26575b9b823e5a778b9fde 100644 (file)
 #include <stdint.h>
 #include <linux/tipc.h>
 #include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <errno.h>
 #include "misc.h"
 
 #define IN_RANGE(val, low, high) ((val) <= (high) && (val) >= (low))
@@ -109,3 +113,19 @@ 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);
+       close(sd);
+}