Check device argument by valid ifindex instead of
guessing it by different device name prefixes like
"eth", "ath", "ens", "enp".

Use __device_ifindex(...) function for this, which needs to
add few more dependencies like str.o, sock.o, link.o to the
Makefile for mausezahn tool.

It resolves issue #159.

Signed-off-by: Vadim Kochan <vadi...@gmail.com>
Suggested-by: Tobias Klauser <tklau...@distanz.ch>
---
 mausezahn/Makefile  |  4 ++++
 staging/mausezahn.c | 10 +++-------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/mausezahn/Makefile b/mausezahn/Makefile
index 08918b5..ca16b65 100644
--- a/mausezahn/Makefile
+++ b/mausezahn/Makefile
@@ -7,6 +7,10 @@ mausezahn-libs =       -lcli \
 
 mausezahn-objs =       str.o \
                        die.o \
+                       dev.o \
+                       sock.o \
+                       link.o \
+                       sysctl.o \
                        xmalloc.o \
                        staging/layer1.o \
                        staging/layer2.o \
diff --git a/staging/mausezahn.c b/staging/mausezahn.c
index 70f1e72..32bcdc5 100644
--- a/staging/mausezahn.c
+++ b/staging/mausezahn.c
@@ -30,6 +30,7 @@
 #include "config.h"
 #include "llist.h"
 #include "die.h"
+#include "dev.h"
 
 int verbose_level = 0;
 
@@ -597,13 +598,8 @@ int getopts (int argc, char *argv[])
                }
                break;
         case 1: // arg_string OR device given => find out!
-               if ( (strncmp(argv[optind],"eth",3)==0) 
-                    || (strncmp(argv[optind],"ath",3)==0)
-                    || 
((strncmp(argv[optind],"lo",2)==0)&&(strncmp(argv[optind],"log",3)!=0))
-                    || (strncmp(argv[optind],"vmnet",5)==0)
-                    || (strncmp(argv[optind],"wifi",4)==0) ) {
-                       // device has been specified!
-                       strncpy (tx.device, argv[optind], 16);
+               if (__device_ifindex(argv[optind]) > 0) {
+                       strncpy(tx.device, argv[optind], 16);
                }
                else { /// arg_string given => no device has been specified -- 
let's find one!
                        strncpy (tx.arg_string, argv[optind], MAX_PAYLOAD_SIZE);
-- 
2.9.3

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to