summaryrefslogtreecommitdiffstats
path: root/utils/iftest.c
blob: 2bbe3a3ef501b6139ef2b99cc9b49dbbbdba1d02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* simple test for index to interface name API */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <net/if.h>

#include <libnfnetlink/libnfnetlink.h>

int main()
{
	int i;
	struct nlif_handle *h;

	h = nlif_open();
	if (h == NULL) {
		perror("nlif_open");
		exit(EXIT_FAILURE);
	}

	nlif_query(h);

	for (i=0; i<64; i++) {
		char name[IFNAMSIZ];
		unsigned int flags;

		if (nlif_index2name(h, i, name) == -1)
			continue;
		if (nlif_get_ifflags(h, i, &flags) == -1)
			continue;
		printf("index (%d) is %s (%s)\n", i, name,
			flags & IFF_RUNNING ? "RUNNING" : "NOT RUNNING");
	}

	nlif_close(h);
}