diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2017-07-17 09:06:36 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-07-17 09:15:46 +0200 |
commit | 3261379f19ad0da4c32e8ab5654a84bf5d17282a (patch) | |
tree | 6a8663871fb9b7987e24b468d81a971cb76e8f0f /trafgen.c | |
parent | 551aa0ee996132e443b5d12cbb6f114ac9aabcd3 (diff) |
trafgen: Delegate creation of rfraw to dev_io API
Simplify a bit of creation rfraw device by delegating it to the dev_io
API, also in case the output device is pcap file the --rfraw option
sets the link type to ieee80211 radio tap.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen.c')
-rw-r--r-- | trafgen.c | 25 |
1 files changed, 9 insertions, 16 deletions
@@ -45,7 +45,6 @@ #include "lockme.h" #include "privs.h" #include "proc.h" -#include "mac80211.h" #include "ioops.h" #include "irq.h" #include "config.h" @@ -85,7 +84,7 @@ struct ctx { unsigned long num; unsigned int cpus; uid_t uid; gid_t gid; - char *device, *device_trans, *rhost; + char *device, *rhost; struct sockaddr_in dest; struct shaper sh; char *packet_str; @@ -1023,7 +1022,7 @@ static unsigned int generate_srand_seed(void) static void on_panic_del_rfmon(void *arg) { - leave_rfmon_mac80211(arg); + dev_io_close(arg); } int main(int argc, char **argv) @@ -1283,15 +1282,6 @@ int main(int argc, char **argv) set_system_socket_memory(vals, array_size(vals)); xlockme(); - if (ctx.rfraw) { - ctx.device_trans = xstrdup(ctx.device); - xfree(ctx.device); - - enter_rfmon_mac80211(ctx.device_trans, &ctx.device); - panic_handler_add(on_panic_del_rfmon, ctx.device); - sleep(0); - } - if (ctx.pcap_in) { ctx.dev_in = dev_io_open(ctx.pcap_in, DEV_IO_IN); if (!ctx.dev_in) @@ -1302,6 +1292,13 @@ int main(int argc, char **argv) if (!ctx.dev_out) panic("Failed to open output device\n"); + if (ctx.rfraw) { + if (dev_io_link_type_set(ctx.dev_out, LINKTYPE_IEEE802_11_RADIOTAP)) + panic("Failed to setup rfraw device\n"); + + panic_handler_add(on_panic_del_rfmon, ctx.dev_out); + } + protos_init(ctx.dev_out); if (shaper_is_set(&ctx.sh) || (ctx.dev_in && dev_io_is_pcap(ctx.dev_in)) @@ -1357,9 +1354,6 @@ int main(int argc, char **argv) die(); } - if (ctx.rfraw) - leave_rfmon_mac80211(ctx.device); - if (set_sock_mem) reset_system_socket_memory(vals, array_size(vals)); @@ -1393,7 +1387,6 @@ thread_out: argv_free(cpp_argv); free(ctx.device); - free(ctx.device_trans); free(ctx.rhost); free(confname); free(ctx.packet_str); |