-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
72 lines (52 loc) · 1.6 KB
/
main.cpp
File metadata and controls
72 lines (52 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <net/if.h>
#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
#include <linux/nl80211.h>
#include <pcap.h>
#include <iostream>
#include <radiotap.h>
using std::cout;
using std::cin;
using std::endl;
bool changeChannel(char *device,int channel){
int frequencyMhz = 2412 + (channel-1) *5;
struct nl_sock *sckt = nl_socket_alloc();
genl_connect(sckt);
struct nl_msg *mesg = nlmsg_alloc();
enum nl80211_commands command = NL80211_CMD_SET_WIPHY;
genlmsg_put(mesg, 0, 0, genl_ctrl_resolve(sckt, "nl80211"), 0, 0, command, 0);
NLA_PUT_U32(mesg, NL80211_ATTR_IFINDEX, if_nametoindex(device));
NLA_PUT_U32(mesg, NL80211_ATTR_WIPHY_FREQ, frequencyMhz);
nl_send_auto_complete(sckt, mesg);
//printf("%d Bytes Sent\n", ret);
nlmsg_free(mesg);
return true;
nla_put_failure:
nlmsg_free(mesg);
//printf("PUT Failure\n");
return false;
}
int main(int argc, char *argv[])
{
char device[100] = "wlan3";
char* dev = device;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t* handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
if (handle == NULL) {
printf("couldn't open device %s: %s\n", dev, errbuf);
return -1;
}
int packet_cnt=0;
while (true) {
bool isTcp=false;
struct pcap_pkthdr* header;
const u_char* packet;
int res = pcap_next_ex(handle, &header, &packet);
//cout << "test";
radiotap radio(packet);
// printf("ext %d nextext %d\n", r_present->ext,(r_present+1)->ext);
cout << endl;
}
return 0;
}