mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 14:49:24 +01:00
monitor: Add option to provide nl80211 family identifier
This commit is contained in:
parent
18652f1f49
commit
9fa506c237
@ -25,6 +25,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@ -310,7 +311,7 @@ done:
|
|||||||
return exit_status;
|
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 nlmon *nlmon = NULL;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
@ -327,7 +328,7 @@ static int process_pcap(struct pcap *pcap)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlmon = nlmon_create();
|
nlmon = nlmon_create(id);
|
||||||
|
|
||||||
while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) {
|
while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) {
|
||||||
uint16_t arphrd_type;
|
uint16_t arphrd_type;
|
||||||
@ -415,6 +416,7 @@ static const struct option main_options[] = {
|
|||||||
{ "read", required_argument, NULL, 'r' },
|
{ "read", required_argument, NULL, 'r' },
|
||||||
{ "write", required_argument, NULL, 'w' },
|
{ "write", required_argument, NULL, 'w' },
|
||||||
{ "analyze", required_argument, NULL, 'a' },
|
{ "analyze", required_argument, NULL, 'a' },
|
||||||
|
{ "nl80211", required_argument, NULL, 'F' },
|
||||||
{ "interface", required_argument, NULL, 'i' },
|
{ "interface", required_argument, NULL, 'i' },
|
||||||
{ "version", no_argument, NULL, 'v' },
|
{ "version", no_argument, NULL, 'v' },
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
@ -426,6 +428,7 @@ int main(int argc, char *argv[])
|
|||||||
const char *reader_path = NULL;
|
const char *reader_path = NULL;
|
||||||
const char *analyze_path = NULL;
|
const char *analyze_path = NULL;
|
||||||
const char *ifname = "nlmon";
|
const char *ifname = "nlmon";
|
||||||
|
uint16_t nl80211_family = GENL_ID_GENERATE;
|
||||||
struct l_signal *signal;
|
struct l_signal *signal;
|
||||||
struct l_netlink *genl;
|
struct l_netlink *genl;
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
@ -434,7 +437,7 @@ int main(int argc, char *argv[])
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
int opt;
|
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);
|
main_options, NULL);
|
||||||
if (opt < 0)
|
if (opt < 0)
|
||||||
break;
|
break;
|
||||||
@ -449,6 +452,26 @@ int main(int argc, char *argv[])
|
|||||||
case 'a':
|
case 'a':
|
||||||
analyze_path = optarg;
|
analyze_path = optarg;
|
||||||
break;
|
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':
|
case 'i':
|
||||||
ifname = optarg;
|
ifname = optarg;
|
||||||
break;
|
break;
|
||||||
@ -501,7 +524,7 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(stderr, "Invalid packet format\n");
|
fprintf(stderr, "Invalid packet format\n");
|
||||||
exit_status = EXIT_FAILURE;
|
exit_status = EXIT_FAILURE;
|
||||||
} else
|
} else
|
||||||
exit_status = process_pcap(pcap);
|
exit_status = process_pcap(pcap, nl80211_family);
|
||||||
|
|
||||||
pcap_close(pcap);
|
pcap_close(pcap);
|
||||||
|
|
||||||
|
@ -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;
|
struct nlmon *nlmon;
|
||||||
|
|
||||||
nlmon = l_new(struct nlmon, 1);
|
nlmon = l_new(struct nlmon, 1);
|
||||||
|
|
||||||
nlmon->id = GENL_ID_GENERATE;
|
nlmon->id = id;
|
||||||
nlmon->req_list = l_queue_new();
|
nlmon->req_list = l_queue_new();
|
||||||
|
|
||||||
return nlmon;
|
return nlmon;
|
||||||
|
@ -28,7 +28,7 @@ struct nlmon;
|
|||||||
struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname);
|
struct nlmon *nlmon_open(const char *ifname, uint16_t id, const char *pathname);
|
||||||
void nlmon_close(struct nlmon *nlmon);
|
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_destroy(struct nlmon *nlmon);
|
||||||
void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv,
|
void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv,
|
||||||
const void *data, uint32_t size);
|
const void *data, uint32_t size);
|
||||||
|
Loading…
Reference in New Issue
Block a user