summaryrefslogtreecommitdiffstats
path: root/utils/iftest.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2012-08-12 20:56:25 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2012-08-12 20:57:42 +0200
commit01db81597502c6016888411983db33b7718ca810 (patch)
tree3f39068d2ea6a85c2aba90b6d5aecaf9109f3273 /utils/iftest.c
parent0df4d39a2a966dcd384ae40419ac4a55378bb4bb (diff)
utils: iftest: pass the device name you want to obtain information for
Instead of brute-force information extraction based on the device index. ./iftest eth0 index (2) is eth0 (NOT RUNNING) (UP) Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'utils/iftest.c')
-rw-r--r--utils/iftest.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/utils/iftest.c b/utils/iftest.c
index 40825a3..63cf163 100644
--- a/utils/iftest.c
+++ b/utils/iftest.c
@@ -7,10 +7,17 @@
#include <libnfnetlink/libnfnetlink.h>
-int main(void)
+int main(int argc, char *argv[])
{
- int i;
+ int idx;
struct nlif_handle *h;
+ char name[IFNAMSIZ];
+ unsigned int flags;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <interface>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
h = nlif_open();
if (h == NULL) {
@@ -20,19 +27,23 @@ int main(void)
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) (%s)\n", i, name,
- flags & IFF_RUNNING ? "RUNNING" : "NOT RUNNING",
- flags & IFF_UP ? "UP" : "DOWN");
+ idx = if_nametoindex(argv[1]);
+
+ /* Superfluous: just to make sure nlif_index2name is working fine */
+ if (nlif_index2name(h, idx, name) == -1) {
+ fprintf(stderr, "Cannot translate device idx=%u\n", idx);
+ exit(EXIT_FAILURE);
}
+ if (nlif_get_ifflags(h, idx, &flags) == -1) {
+ fprintf(stderr, "Cannot get flags for device `%s'\n", argv[1]);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("index (%d) is %s (%s) (%s)\n", idx, argv[1],
+ flags & IFF_RUNNING ? "RUNNING" : "NOT RUNNING",
+ flags & IFF_UP ? "UP" : "DOWN");
+
nlif_close(h);
return EXIT_SUCCESS;
}