Blame src/nl-link-name2ifindex.c
|
Packit Service |
f991dd |
/* SPDX-License-Identifier: LGPL-2.1-only */
|
|
Packit Service |
f991dd |
/*
|
|
Packit Service |
f991dd |
* src/nl-link-name2ifindex.c Transform a interface name to its index
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
f991dd |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
f991dd |
* License as published by the Free Software Foundation version 2.1
|
|
Packit Service |
f991dd |
* of the License.
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
|
|
Packit Service |
f991dd |
*/
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
#include <netlink/cli/utils.h>
|
|
Packit Service |
f991dd |
#include <netlink/cli/link.h>
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
#include <linux/netlink.h>
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
static void print_usage(void)
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
printf("Usage: nl-link-name2ifindex <name>\n");
|
|
Packit Service |
f991dd |
exit(0);
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
int main(int argc, char *argv[])
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
struct nl_sock *sock;
|
|
Packit Service |
f991dd |
struct nl_cache *link_cache;
|
|
Packit Service |
f991dd |
uint32_t ifindex;
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
if (argc < 2)
|
|
Packit Service |
f991dd |
print_usage();
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
sock = nl_cli_alloc_socket();
|
|
Packit Service |
f991dd |
nl_cli_connect(sock, NETLINK_ROUTE);
|
|
Packit Service |
f991dd |
link_cache = nl_cli_link_alloc_cache(sock);
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
if (!(ifindex = rtnl_link_name2i(link_cache, argv[1])))
|
|
Packit Service |
f991dd |
nl_cli_fatal(ENOENT, "Interface \"%s\" does not exist",
|
|
Packit Service |
f991dd |
argv[1]);
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
printf("%u\n", ifindex);
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
return 0;
|
|
Packit Service |
f991dd |
}
|