summaryrefslogtreecommitdiff
path: root/netsniff-ng.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-04-20 12:43:08 +0300
committerTobias Klauser <tklauser@distanz.ch>2015-04-21 16:44:15 +0200
commitdce80974dcd2114ebb4a3ed3060d4d636cbb9d1d (patch)
tree9fc6c6bf864695f06b98dbb3ef4c18d1105604b2 /netsniff-ng.c
parent9278bb65e810156ed1074e693fce14e7ecf145e8 (diff)
netsniff-ng: Delete rfmon mac80211 device in case of panic
netsniff-ng does not delete created rfmon device in case of panic (for example - bad pcap filter expression), so added ability to add callback func when panic will be happen and delete rfmon device. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'netsniff-ng.c')
-rw-r--r--netsniff-ng.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 2eafe31..c0d70c8 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -184,6 +184,20 @@ static inline bool dump_to_pcap(struct ctx *ctx)
return ctx->dump;
}
+static void on_panic_del_rfmon(void *arg)
+{
+ leave_rfmon_mac80211(arg);
+}
+
+static inline void setup_rfmon_mac80211_dev(struct ctx *ctx, char **rfmon_dev)
+{
+ ctx->device_trans = xstrdup(*rfmon_dev);
+ xfree(*rfmon_dev);
+
+ enter_rfmon_mac80211(ctx->device_trans, rfmon_dev);
+ panic_func_add(on_panic_del_rfmon, *rfmon_dev);
+}
+
static void pcap_to_xmit(struct ctx *ctx)
{
uint8_t *out = NULL;
@@ -227,10 +241,8 @@ static void pcap_to_xmit(struct ctx *ctx)
}
if (ctx->rfraw) {
- ctx->device_trans = xstrdup(ctx->device_out);
- xfree(ctx->device_out);
+ setup_rfmon_mac80211_dev(ctx, &ctx->device_out);
- enter_rfmon_mac80211(ctx->device_trans, &ctx->device_out);
if (ctx->link_type != LINKTYPE_IEEE802_11 &&
ctx->link_type != LINKTYPE_IEEE802_11_RADIOTAP)
panic("Wrong linktype of pcap!\n");
@@ -1464,12 +1476,8 @@ int main(int argc, char **argv)
}
if (device_mtu(ctx.device_in) || !strncmp("any", ctx.device_in, strlen(ctx.device_in))) {
- if (ctx.rfraw) {
- ctx.device_trans = xstrdup(ctx.device_in);
- xfree(ctx.device_in);
-
- enter_rfmon_mac80211(ctx.device_trans, &ctx.device_in);
- }
+ if (ctx.rfraw)
+ setup_rfmon_mac80211_dev(&ctx, &ctx.device_in);
ctx.link_type = pcap_devtype_to_linktype(ctx.device_in);