From: Tobias Klauser Date: Fri, 9 Aug 2013 10:04:49 +0000 (+0200) Subject: dev: Integrate `promisc' module into `dev' module X-Git-Tag: v0.5.8-rc3~21 X-Git-Url: https://repo.or.cz/w/netsniff-ng.git/commitdiff_plain/a2e70ae5b06ac6fa09cce3848c2ed795967b174f 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 --- diff --git a/dev.c b/dev.c index 9c7af154..b3249e6c 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 4bfc3f05..2d5f0569 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 93446259..b2d3e49e 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 b7ef9186..81100db0 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 8e8b2632..0f35d043 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 88113288..2ddddfdb 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 56f6e4be..00000000 --- a/promisc.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include - -#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 3dc275f8..00000000 --- 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 */