2 * src/nl-link-ifindex2name.c Transform a interface index to its name
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
14 int main(int argc, char **argv)
16 struct nl_handle *nlh;
17 struct nl_cache *link_cache;
18 int err = -1, ifindex;
22 if (nltool_init(argc, argv) < 0)
25 if (argc < 2 || !strcmp(argv[1], "-h")) {
26 fprintf(stderr, "Usage: nl-link-ifindex2name <ifindex>\n");
30 nlh = nl_handle_alloc_nondefault(nltool_cbset);
34 if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
37 link_cache = nltool_alloc_link_cache(nlh);
41 ifindex = strtoul(argv[1], NULL, 0);
43 if (!(name = rtnl_link_i2name(link_cache, ifindex, dst, sizeof(dst))))
44 fprintf(stderr, "Interface index %d does not exist\n", ifindex);
48 nl_cache_free(link_cache);
52 nl_handle_destroy(nlh);