dect
/
libnl
Archived
13
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
libnl/src/nl-link-name2ifindex.c

42 lines
943 B
C
Raw Normal View History

2007-09-14 23:28:01 +00:00
/*
* src/nl-link-name2ifindex.c Transform a interface name to its index
*
* 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.
*
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
2007-09-14 23:28:01 +00:00
*/
#include <netlink/cli/utils.h>
#include <netlink/cli/link.h>
2007-09-14 23:28:01 +00:00
static void print_usage(void)
{
printf("Usage: nl-link-name2ifindex <name>\n");
exit(0);
}
2007-09-14 23:28:01 +00:00
int main(int argc, char *argv[])
{
struct nl_sock *sock;
2007-09-14 23:28:01 +00:00
struct nl_cache *link_cache;
uint32_t ifindex;
2007-09-14 23:28:01 +00:00
if (argc < 2)
print_usage();
2007-09-14 23:28:01 +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
if (!(ifindex = rtnl_link_name2i(link_cache, argv[1])))
nl_cli_fatal(ENOENT, "Interface \"%s\" does not exist",
argv[1]);
2007-09-14 23:28:01 +00:00
printf("%u\n", ifindex);
2007-09-14 23:28:01 +00:00
return 0;
2007-09-14 23:28:01 +00:00
}