summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-08-09 12:04:49 +0200
committerTobias Klauser <tklauser@distanz.ch>2013-08-09 12:04:49 +0200
commita2e70ae5b06ac6fa09cce3848c2ed795967b174f (patch)
tree214b9c1e15a502f4cb57939fceec371c1a970f83
parentaf0c1f5f89750f16054c988937e180764c411c20 (diff)
dev: Integrate `promisc' module into `dev' module
Since entering/leaving promiscuous mode also is a device specific function and all users of the `promisc' module also use `dev', integrate it there. Also rename the functions to have a `device_' prefix like the other functions in the module. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--dev.c21
-rw-r--r--dev.h2
-rw-r--r--ifpps.c5
-rw-r--r--ifpps/Makefile1
-rw-r--r--netsniff-ng.c10
-rw-r--r--netsniff-ng/Makefile1
-rw-r--r--promisc.c27
-rw-r--r--promisc.h7
8 files changed, 30 insertions, 44 deletions
diff --git a/dev.c b/dev.c
index 9c7af15..b3249e6 100644
--- a/dev.c
+++ b/dev.c
@@ -189,3 +189,24 @@ u32 device_bitrate(const char *ifname)
return scopper ? : swireless;
}
+
+short device_enter_promiscuous_mode(const char *ifname)
+{
+ short ifflags;
+
+ if (!strncmp("any", ifname, strlen("any")))
+ return 0;
+
+ ifflags = device_get_flags(ifname);
+ device_set_flags(ifname, ifflags | IFF_PROMISC);
+
+ return ifflags;
+}
+
+void device_leave_promiscuous_mode(const char *ifname, short oldflags)
+{
+ if (!strncmp("any", ifname, strlen("any")))
+ return;
+
+ device_set_flags(ifname, oldflags);
+}
diff --git a/dev.h b/dev.h
index 4bfc3f0..2d5f056 100644
--- a/dev.h
+++ b/dev.h
@@ -12,5 +12,7 @@ extern short device_get_flags(const char *ifname);
extern void device_set_flags(const char *ifname, const short flags);
extern int device_up_and_running(const char *ifname);
extern u32 device_bitrate(const char *ifname);
+extern short device_enter_promiscuous_mode(const char *ifname);
+extern void device_leave_promiscuous_mode(const char *ifname, short oldflags);
#endif /* DEV_H */
diff --git a/ifpps.c b/ifpps.c
index 9344625..b2d3e49 100644
--- a/ifpps.c
+++ b/ifpps.c
@@ -27,7 +27,6 @@
#include "link.h"
#include "xmalloc.h"
#include "ioops.h"
-#include "promisc.h"
#include "cpus.h"
#include "config.h"
#include "built_in.h"
@@ -1383,10 +1382,10 @@ int main(int argc, char **argv)
cpu_hits = xzmalloc(cpus * sizeof(*cpu_hits));
if (promisc)
- ifflags = enter_promiscuous_mode(ifname);
+ ifflags = device_enter_promiscuous_mode(ifname);
ret = func_main(ifname, interval, top_cpus, suppress_warnings);
if (promisc)
- leave_promiscuous_mode(ifname, ifflags);
+ device_leave_promiscuous_mode(ifname, ifflags);
stats_release(&stats_old);
stats_release(&stats_new);
diff --git a/ifpps/Makefile b/ifpps/Makefile
index b7ef918..81100db 100644
--- a/ifpps/Makefile
+++ b/ifpps/Makefile
@@ -2,7 +2,6 @@ ifpps-libs = $(shell pkg-config --libs ncurses)
ifpps-objs = xmalloc.o \
ioops.o \
- promisc.o \
str.o \
link.o \
sock.o \
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 8e8b263..0f35d04 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -26,7 +26,7 @@
#include "ring_rx.h"
#include "ring_tx.h"
#include "mac80211.h"
-#include "promisc.h"
+#include "dev.h"
#include "built_in.h"
#include "pcap_io.h"
#include "privs.h"
@@ -394,7 +394,7 @@ static void receive_to_xmit(struct ctx *ctx)
dissector_init_all(ctx->print_mode);
if (ctx->promiscuous)
- ifflags = enter_promiscuous_mode(ctx->device_in);
+ ifflags = device_enter_promiscuous_mode(ctx->device_in);
if (ctx->kpull)
interval = ctx->kpull;
@@ -490,7 +490,7 @@ static void receive_to_xmit(struct ctx *ctx)
destroy_rx_ring(rx_sock, &rx_ring);
if (ctx->promiscuous)
- leave_promiscuous_mode(ctx->device_in, ifflags);
+ device_leave_promiscuous_mode(ctx->device_in, ifflags);
close(tx_sock);
close(rx_sock);
@@ -938,7 +938,7 @@ static void recv_only_or_dump(struct ctx *ctx)
}
if (ctx->promiscuous)
- ifflags = enter_promiscuous_mode(ctx->device_in);
+ ifflags = device_enter_promiscuous_mode(ctx->device_in);
if (dump_to_pcap(ctx) && __pcap_io->init_once_pcap)
__pcap_io->init_once_pcap();
@@ -1003,7 +1003,7 @@ static void recv_only_or_dump(struct ctx *ctx)
destroy_rx_ring(sock, &rx_ring);
if (ctx->promiscuous)
- leave_promiscuous_mode(ctx->device_in, ifflags);
+ device_leave_promiscuous_mode(ctx->device_in, ifflags);
if (ctx->rfraw)
leave_rfmon_mac80211(ctx->device_in);
diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile
index 8811328..2ddddfd 100644
--- a/netsniff-ng/Makefile
+++ b/netsniff-ng/Makefile
@@ -37,7 +37,6 @@ netsniff-ng-objs = dissector.o \
proto_vlan_q_in_q.o \
proto_mpls_unicast.o \
proto_80211_mac_hdr.o \
- promisc.o \
privs.o \
proc.o \
dev.o \
diff --git a/promisc.c b/promisc.c
deleted file mode 100644
index 56f6e4b..0000000
--- a/promisc.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <string.h>
-#include <sys/socket.h>
-#include <linux/if.h>
-
-#include "promisc.h"
-#include "dev.h"
-
-short enter_promiscuous_mode(const char *ifname)
-{
- short ifflags;
-
- if (!strncmp("any", ifname, strlen("any")))
- return 0;
-
- ifflags = device_get_flags(ifname);
- device_set_flags(ifname, ifflags | IFF_PROMISC);
-
- return ifflags;
-}
-
-void leave_promiscuous_mode(const char *ifname, short oldflags)
-{
- if (!strncmp("any", ifname, strlen("any")))
- return;
-
- device_set_flags(ifname, oldflags);
-}
diff --git a/promisc.h b/promisc.h
deleted file mode 100644
index 3dc275f..0000000
--- a/promisc.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef PROMISC_H
-#define PROMISC_H
-
-extern short enter_promiscuous_mode(const char *ifname);
-extern void leave_promiscuous_mode(const char *ifname, short oldflags);
-
-#endif /* PROMISC_H */