1 /* SPDX-License-Identifier: LGPL-2.1-only */ 2 /* 3 * Copyright (c) 2003-2009 Thomas Graf <[email protected]> 4 */ 5 6 #include "nl-default.h" 7 8 #include <linux/netlink.h> 9 10 #include <netlink/cli/utils.h> 11 #include <netlink/cli/link.h> 12 print_usage(void)13static void print_usage(void) 14 { 15 printf("Usage: nl-link-ifindex2name <ifindex>\n"); 16 exit(0); 17 } 18 main(int argc,char * argv[])19int main(int argc, char *argv[]) 20 { 21 struct nl_sock *sock; 22 struct nl_cache *link_cache; 23 char name[IFNAMSIZ]; 24 uint32_t ifindex; 25 26 if (argc < 2) 27 print_usage(); 28 29 sock = nl_cli_alloc_socket(); 30 nl_cli_connect(sock, NETLINK_ROUTE); 31 link_cache = nl_cli_link_alloc_cache(sock); 32 33 ifindex = nl_cli_parse_u32(argv[1]); 34 35 if (!rtnl_link_i2name(link_cache, ifindex, name, sizeof(name))) 36 nl_cli_fatal(ENOENT, "Interface index %d does not exist", 37 ifindex); 38 39 printf("%s\n", name); 40 41 return 0; 42 } 43