From ac5fd9168efaa4e149340340805b1be7425d8834 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Tue, 4 Jun 2013 10:32:48 +0200 Subject: xutils: break out promisc mode functions Put them separately for the sake of maintanence. Signed-off-by: Daniel Borkmann --- ifpps.c | 1 + ifpps/Makefile | 1 + netsniff-ng.c | 1 + netsniff-ng/Makefile | 1 + promisc.c | 25 +++++++++++++++++++++++++ promisc.h | 7 +++++++ xutils.c | 21 --------------------- xutils.h | 2 -- 8 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 promisc.c create mode 100644 promisc.h diff --git a/ifpps.c b/ifpps.c index e835660..340b1a3 100644 --- a/ifpps.c +++ b/ifpps.c @@ -21,6 +21,7 @@ #include "xmalloc.h" #include "xutils.h" #include "ioops.h" +#include "promisc.h" #include "cpus.h" #include "built_in.h" diff --git a/ifpps/Makefile b/ifpps/Makefile index 8b055b4..57816ac 100644 --- a/ifpps/Makefile +++ b/ifpps/Makefile @@ -3,5 +3,6 @@ ifpps-libs = $(shell pkg-config --libs ncurses) ifpps-objs = xmalloc.o \ ioops.o \ xutils.o \ + promisc.o \ str.o \ ifpps.o diff --git a/netsniff-ng.c b/netsniff-ng.c index 2005f9b..b0b6f51 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -27,6 +27,7 @@ #include "ring_tx.h" #include "mac80211.h" #include "xutils.h" +#include "promisc.h" #include "built_in.h" #include "pcap_io.h" #include "bpf.h" diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile index 7f5a490..39412a6 100644 --- a/netsniff-ng/Makefile +++ b/netsniff-ng/Makefile @@ -32,6 +32,7 @@ netsniff-ng-objs = dissector.o \ proto_vlan_q_in_q.o \ proto_mpls_unicast.o \ proto_80211_mac_hdr.o \ + promisc.o \ str.o \ irq.o \ iosched.o \ diff --git a/promisc.c b/promisc.c new file mode 100644 index 0000000..721da18 --- /dev/null +++ b/promisc.c @@ -0,0 +1,25 @@ +#include + +#include "promisc.h" +#include "xutils.h" + +short enter_promiscuous_mode(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(char *ifname, short oldflags) +{ + if (!strncmp("any", ifname, strlen("any"))) + return; + + device_set_flags(ifname, oldflags); +} diff --git a/promisc.h b/promisc.h new file mode 100644 index 0000000..b290b92 --- /dev/null +++ b/promisc.h @@ -0,0 +1,7 @@ +#ifndef PROMISC_H +#define PROMISC_H + +extern short enter_promiscuous_mode(char *ifname); +extern void leave_promiscuous_mode(char *ifname, short oldflags); + +#endif /* PROMISC_H */ diff --git a/xutils.c b/xutils.c index e3e7f6f..991ff5b 100644 --- a/xutils.c +++ b/xutils.c @@ -569,27 +569,6 @@ void register_signal_f(int signal, void (*handler)(int), int flags) sigaction(signal, &saction, NULL); } -short enter_promiscuous_mode(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(char *ifname, short oldflags) -{ - if (!strncmp("any", ifname, strlen("any"))) - return; - - device_set_flags(ifname, oldflags); -} - int device_up_and_running(char *ifname) { if (!ifname) diff --git a/xutils.h b/xutils.h index eda512d..8cf1af2 100644 --- a/xutils.h +++ b/xutils.h @@ -52,8 +52,6 @@ extern int get_system_socket_mem(int which); extern void set_system_socket_mem(int which, int val); extern void register_signal(int signal, void (*handler)(int)); extern void register_signal_f(int signal, void (*handler)(int), int flags); -extern short enter_promiscuous_mode(char *ifname); -extern void leave_promiscuous_mode(char *ifname, short oldflags); extern int device_up_and_running(char *ifname); extern void set_epoll_descriptor(int fd_epoll, int action, int fd_toadd, int events); extern int set_epoll_descriptor2(int fd_epoll, int action, int fd_toadd, int events); -- cgit v1.2.3-54-g00ecf