1 /* simple test for index to interface name API */
9 #include <libnfnetlink/libnfnetlink.h>
11 int main(int argc
, char *argv
[])
14 struct nlif_handle
*h
;
19 fprintf(stderr
, "Usage: %s <interface>\n", argv
[0]);
29 if (nlif_query(h
) == -1) {
30 fprintf(stderr
, "failed query to retrieve interfaces: %s\n",
35 idx
= if_nametoindex(argv
[1]);
37 /* Superfluous: just to make sure nlif_index2name is working fine */
38 if (nlif_index2name(h
, idx
, name
) == -1)
39 fprintf(stderr
, "Cannot translate device idx=%u\n", idx
);
41 if (nlif_get_ifflags(h
, idx
, &flags
) == -1) {
42 fprintf(stderr
, "Cannot get flags for device `%s'\n", argv
[1]);
46 printf("index (%d) is %s (%s) (%s)\n", idx
, argv
[1],
47 flags
& IFF_RUNNING
? "RUNNING" : "NOT RUNNING",
48 flags
& IFF_UP
? "UP" : "DOWN");