summaryrefslogtreecommitdiff
path: root/dev.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-04-17 22:04:21 +0300
committerTobias Klauser <tklauser@distanz.ch>2015-04-20 09:31:43 +0200
commitf43bbe9e895a05a71ebfa5fb676f068621bd5014 (patch)
treefe2be9b9c87e5bec73deb60bdfb9c9205a492a27 /dev.c
parent47a7037955bfa7405a0a676f214c26d136b8ca9a (diff)
mac80211: Check existence of generated monX device
Fix then case when netsniff-ng fails if there is already an existing monX device while generating one. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'dev.c')
-rw-r--r--dev.c15
1 files changed, 12 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;