From 9fa506c2371e9b16a347e5b134d20f326f399e3c Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Fri, 15 Aug 2014 23:59:33 +0200 Subject: [PATCH] monitor: Add option to provide nl80211 family identifier --- monitor/main.c | 31 +++++++++++++++++++++++++++---- monitor/nlmon.c | 4 ++-- monitor/nlmon.h | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/monitor/main.c b/monitor/main.c index c7902fe8..54b5a31e 100644 --- a/monitor/main.c +++ b/monitor/main.c @@ -25,6 +25,7 @@ #endif #include +#include #include #include #include @@ -310,7 +311,7 @@ done: return exit_status; } -static int process_pcap(struct pcap *pcap) +static int process_pcap(struct pcap *pcap, uint16_t id) { struct nlmon *nlmon = NULL; struct timeval tv; @@ -327,7 +328,7 @@ static int process_pcap(struct pcap *pcap) return EXIT_FAILURE; } - nlmon = nlmon_create(); + nlmon = nlmon_create(id); while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) { uint16_t arphrd_type; @@ -415,6 +416,7 @@ static const struct option main_options[] = { { "read", required_argument, NULL, 'r' }, { "write", required_argument, NULL, 'w' }, { "analyze", required_argument, NULL, 'a' }, + { "nl80211", required_argument, NULL, 'F' }, { "interface", required_argument, NULL, 'i' }, { "version", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, @@ -426,6 +428,7 @@ int main(int argc, char *argv[]) const char *reader_path = NULL; const char *analyze_path = NULL; const char *ifname = "nlmon"; + uint16_t nl80211_family = GENL_ID_GENERATE; struct l_signal *signal; struct l_netlink *genl; sigset_t mask; @@ -434,7 +437,7 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "r:w:a:i:vh", + opt = getopt_long(argc, argv, "r:w:a:F:i:vh", main_options, NULL); if (opt < 0) break; @@ -449,6 +452,26 @@ int main(int argc, char *argv[]) case 'a': analyze_path = optarg; break; + case 'F': + if (strlen(optarg) > 3) { + if (!strncasecmp(optarg, "0x", 2) && + !isxdigit(optarg[2])) { + usage(); + return EXIT_FAILURE; + } + nl80211_family = strtoul(optarg + 2, NULL, 16); + } else { + if (!isdigit(optarg[0])) { + usage(); + return EXIT_FAILURE; + } + nl80211_family = strtoul(optarg, NULL, 10); + } + if (nl80211_family == GENL_ID_GENERATE) { + usage(); + return EXIT_FAILURE; + } + break; case 'i': ifname = optarg; break; @@ -501,7 +524,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid packet format\n"); exit_status = EXIT_FAILURE; } else - exit_status = process_pcap(pcap); + exit_status = process_pcap(pcap, nl80211_family); pcap_close(pcap); diff --git a/monitor/nlmon.c b/monitor/nlmon.c index 988e5ef5..98872487 100644 --- a/monitor/nlmon.c +++ b/monitor/nlmon.c @@ -1624,13 +1624,13 @@ static void nlmon_message(struct nlmon *nlmon, const struct timeval *tv, } } -struct nlmon *nlmon_create(void) +struct nlmon *nlmon_create(uint16_t id) { struct nlmon *nlmon; nlmon = l_new(struct nlmon, 1); - nlmon->id = GENL_ID_GENERATE; + nlmon->id = id; nlmon->req_list = l_queue_new(); return nlmon; diff --git a/monitor/nlmon.h b/monitor/nlmon.h index 99abaff7..1eef4b7c 100644 --- a/monitor/nlmon.h +++ b/monitor/nlmon.h @@ -28,7 +28,7 @@ struct nlmon; struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname); void nlmon_close(struct nlmon *nlmon); -struct nlmon *nlmon_create(void); +struct nlmon *nlmon_create(uint16_t id); void nlmon_destroy(struct nlmon *nlmon); void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv, const void *data, uint32_t size);