dev: Integrate `promisc' module into `dev' module
authorTobias Klauser <tklauser@distanz.ch>
Fri, 9 Aug 2013 10:04:49 +0000 (9 12:04 +0200)
committerTobias Klauser <tklauser@distanz.ch>
Fri, 9 Aug 2013 10:04:49 +0000 (9 12:04 +0200)
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>
dev.c
dev.h
ifpps.c
ifpps/Makefile
netsniff-ng.c
netsniff-ng/Makefile
promisc.c [deleted file]
promisc.h [deleted file]

diff --git a/dev.c b/dev.c
index 9c7af15..b3249e6 100644 (file)
--- 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 (file)
--- 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 (file)
--- 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);
index b7ef918..81100db 100644 (file)
@@ -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 \
index 8e8b263..0f35d04 100644 (file)
@@ -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);
index 8811328..2ddddfd 100644 (file)
@@ -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 (file)
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 (file)
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 */