2007-09-14 23:28:01 +00:00
|
|
|
/*
|
|
|
|
* src/nl-link-ifindex2name.c Transform a interface index to its name
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
2009-12-16 15:20:46 +00:00
|
|
|
* Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
|
2007-09-14 23:28:01 +00:00
|
|
|
*/
|
|
|
|
|
2009-12-16 15:20:46 +00:00
|
|
|
#include <netlink/cli/utils.h>
|
|
|
|
#include <netlink/cli/link.h>
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2008-05-22 22:02:02 +00:00
|
|
|
static void print_usage(void)
|
2007-09-14 23:28:01 +00:00
|
|
|
{
|
2008-05-22 22:02:02 +00:00
|
|
|
printf("Usage: nl-link-ifindex2name <ifindex>\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2008-05-22 22:02:02 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct nl_sock *sock;
|
|
|
|
struct nl_cache *link_cache;
|
|
|
|
char name[IFNAMSIZ];
|
|
|
|
uint32_t ifindex;
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2008-05-22 22:02:02 +00:00
|
|
|
if (argc < 2)
|
|
|
|
print_usage();
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2009-12-16 15:20:46 +00:00
|
|
|
sock = nl_cli_alloc_socket();
|
|
|
|
nl_cli_connect(sock, NETLINK_ROUTE);
|
|
|
|
link_cache = nl_cli_link_alloc_cache(sock);
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2009-12-16 15:20:46 +00:00
|
|
|
ifindex = nl_cli_parse_u32(argv[1]);
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2008-05-22 22:02:02 +00:00
|
|
|
if (!rtnl_link_i2name(link_cache, ifindex, name, sizeof(name)))
|
2009-12-16 15:20:46 +00:00
|
|
|
nl_cli_fatal(ENOENT, "Interface index %d does not exist",
|
|
|
|
ifindex);
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2008-05-22 22:02:02 +00:00
|
|
|
printf("%s\n", name);
|
2007-09-14 23:28:01 +00:00
|
|
|
|
2008-05-22 22:02:02 +00:00
|
|
|
return 0;
|
2007-09-14 23:28:01 +00:00
|
|
|
}
|