-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
executable file
·105 lines (87 loc) · 2.61 KB
/
main.c
File metadata and controls
executable file
·105 lines (87 loc) · 2.61 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <pcap.h>
#include <pcap/pcap.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
#define SIZE 60
char pwr;
uint8_t my_mac[6];
int pwr_arr[100];
int k = 0;
struct radiotap_header {
uint8_t it_version;
uint8_t it_pad;
uint16_t it_length;
uint64_t it_present_flags;
uint8_t it_flags;
uint8_t it_data_Rate;
uint16_t it_channel_frequency;
uint16_t it_channel_flags;
uint8_t it_antenna_signal;
uint8_t it_null;
uint16_t it_RX_flags;
uint8_t it_antenna_signal_2;
uint8_t it_null_2;
};
struct ieee80211_header {
uint8_t type_subtype;
uint8_t flags;
uint16_t duration;
uint8_t mac_add_destination[6];
uint8_t mac_add_source[6];
uint8_t BSSID[6];
uint16_t fragment_sequence;
};
void usage() {
printf("syntax : bob_0x10_hackathon <filename> <Mac Address>\n");
printf("sample : bob_0x10_hackathon demo.pcap FF:FF:FF:FF:FF:FF\n");
}
void my_packet_handler( u_char *args, const struct pcap_pkthdr *header, const u_char *packet) {
struct radiotap_header *radio_hdr;
struct ieee80211_header *ieee_hdr;
radio_hdr = (struct radiotap_header *)packet;
ieee_hdr = (struct ieee80211_header *)(packet + radio_hdr->it_length);
pwr = radio_hdr->it_antenna_signal;
if (memcmp(my_mac, ieee_hdr->mac_add_source, 6) == 0){
pwr_arr[k++] = pwr;
}
return;
}
int main(int argc, char *argv[])
{
if (argc != 3) {
usage();
return -1;
}
char error_buffer[PCAP_ERRBUF_SIZE];
pcap_t *handle = pcap_open_offline(argv[1], error_buffer);
char *device;
int total_packet_count = -1;
u_char *my_arguments = NULL;
device = pcap_lookupdev(error_buffer);
char *str = argv[2];
char t[4];
for(int i=0; i<6; i++){
memcpy(t, (str+i*3), 3);
t[3] = '\0';
*(my_mac +i) = (uint8_t)strtoul(t, NULL, 16);
}
pcap_loop(handle, total_packet_count, my_packet_handler, my_arguments);
int temp;
for(int i = 0; i < k ; i++){
for(int j = 0; j < k-1; j++){
if(pwr_arr[j] > pwr_arr[i]){
temp = pwr_arr[j];
pwr_arr[j] = pwr_arr[j+1];
pwr_arr[j+1] = temp;
}
}
}
printf("Middle num : %d\n", pwr_arr[k/2]);
int mid_signal = pwr_arr[k/2];
return 0;
}