Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / libnfnetlink / utils / iftest.c
blob02f580755b4b2efae45d685be6f3c37fe7ace176
1 /* simple test for index to interface name API */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <errno.h>
7 #include <net/if.h>
9 #include <libnfnetlink/libnfnetlink.h>
11 int main(int argc, char *argv[])
13 int idx;
14 struct nlif_handle *h;
15 char name[IFNAMSIZ];
16 unsigned int flags;
18 if (argc != 2) {
19 fprintf(stderr, "Usage: %s <interface>\n", argv[0]);
20 exit(EXIT_FAILURE);
23 h = nlif_open();
24 if (h == NULL) {
25 perror("nlif_open");
26 exit(EXIT_FAILURE);
29 if (nlif_query(h) == -1) {
30 fprintf(stderr, "failed query to retrieve interfaces: %s\n",
31 strerror(errno));
32 exit(EXIT_FAILURE);
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]);
43 exit(EXIT_FAILURE);
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");
50 nlif_close(h);
51 return EXIT_SUCCESS;