Re: [netsniff-ng] [PATCH] mac80211: Check existing of generated monX device

2015-04-21 Thread Daniel Borkmann

Hi Vadim,

On 04/17/2015 09:04 PM, Vadim Kochan wrote:

From: Vadim Kochan vadi...@gmail.com

Fixed case when netsniff fails if there is already existing monX device
while generating.

Signed-off-by: Vadim Kochan vadi...@gmail.com

...

+int device_ifindex(const char *ifname)
+{
+   int index = device_ifindex_get(ifname);
+   if (unlikely(index = 0))


This test should be  0 only as ifindex 0 would mean to
capture on any device.

So starting netsniff-ng w/o any arguments would not work
anymore otherwise, fix up:

  
https://github.com/netsniff-ng/netsniff-ng/commit/42ca7e42aa76ee52499ae82370d11d044e811f35


+   panic(Cannot get ifindex from device!\n);
+
+   return index;
+}


Cheers,
Daniel

--
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.


Re: [netsniff-ng] [PATCH] mac80211: Check existing of generated monX device

2015-04-21 Thread Vadim Kochan
On Tue, Apr 21, 2015 at 12:30:07PM +0200, Daniel Borkmann wrote:
 Hi Vadim,
 
 On 04/17/2015 09:04 PM, Vadim Kochan wrote:
 From: Vadim Kochan vadi...@gmail.com
 
 Fixed case when netsniff fails if there is already existing monX device
 while generating.
 
 Signed-off-by: Vadim Kochan vadi...@gmail.com
 ...
 +int device_ifindex(const char *ifname)
 +{
 +int index = device_ifindex_get(ifname);
 +if (unlikely(index = 0))
 
 This test should be  0 only as ifindex 0 would mean to
 capture on any device.
 
 So starting netsniff-ng w/o any arguments would not work
 anymore otherwise, fix up:
 
   
 https://github.com/netsniff-ng/netsniff-ng/commit/42ca7e42aa76ee52499ae82370d11d044e811f35
 
 +panic(Cannot get ifindex from device!\n);
 +
 +return index;
 +}
 
 Cheers,
 Daniel

Fuf, thank you! And sorry for this BUG!

-- 
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.


[netsniff-ng] [PATCH] mac80211: Check existing of generated monX device

2015-04-20 Thread Vadim Kochan
From: Vadim Kochan vadi...@gmail.com

Fixed case when netsniff fails if there is already existing monX device
while generating.

Signed-off-by: Vadim Kochan vadi...@gmail.com
---
 dev.c  | 15 ---
 dev.h  |  1 +
 mac80211.c |  4 
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/dev.c b/dev.c
index b3249e6..45659a8 100644
--- a/dev.c
+++ b/dev.c
@@ -13,7 +13,7 @@
 #include link.h
 #include built_in.h
 
-int device_ifindex(const char *ifname)
+int device_ifindex_get(const char *ifname)
 {
int ret, sock, index;
struct ifreq ifr;
@@ -27,8 +27,8 @@ int device_ifindex(const char *ifname)
strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
 
ret = ioctl(sock, SIOCGIFINDEX, ifr);
-   if (unlikely(ret))
-   panic(Cannot get ifindex from device!\n);
+   if (ret)
+   return -1;
 
index = ifr.ifr_ifindex;
close(sock);
@@ -36,6 +36,15 @@ int device_ifindex(const char *ifname)
return index;
 }
 
+int device_ifindex(const char *ifname)
+{
+   int index = device_ifindex_get(ifname);
+   if (unlikely(index = 0))
+   panic(Cannot get ifindex from device!\n);
+
+   return index;
+}
+
 int device_type(const char *ifname)
 {
int ret, sock, type;
diff --git a/dev.h b/dev.h
index 2d5f056..adb1c43 100644
--- a/dev.h
+++ b/dev.h
@@ -7,6 +7,7 @@
 extern size_t device_mtu(const char *ifname);
 extern int device_address(const char *ifname, int af, struct sockaddr_storage 
*ss);
 extern int device_ifindex(const char *ifname);
+extern int device_ifindex_get(const char *ifname);
 extern int device_type(const char *ifname);
 extern short device_get_flags(const char *ifname);
 extern void device_set_flags(const char *ifname, const short flags);
diff --git a/mac80211.c b/mac80211.c
index c089574..09f15b7 100644
--- a/mac80211.c
+++ b/mac80211.c
@@ -226,6 +226,10 @@ void enter_rfmon_mac80211(const char *device, char 
**mondev)
char mondevice[32];
 
slprintf(mondevice, sizeof(mondevice), mon%u, n);
+
+   if (device_ifindex_get(mondevice)  0)
+   continue;
+
ret = nl80211_add_mon_if(nlstate, device, mondevice);
if (ret == 0) {
*mondev = xstrdup(mondevice);
-- 
2.3.1

-- 
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.