-
Notifications
You must be signed in to change notification settings - Fork 6
/
check_alive.c
58 lines (47 loc) · 1.24 KB
/
check_alive.c
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
// check_alive by Rodizio. Checks for incoming wifibroadcast packets. GPL2 licensed.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <resolv.h>
#include <string.h>
#include <utime.h>
#include <unistd.h>
#include <getopt.h>
#include <pcap.h>
#include <endian.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "lib.h"
wifibroadcast_rx_status_t *status_memory_open(void) {
int fd;
for(;;) {
fd = shm_open("/wifibroadcast_rx_status_0", O_RDWR, S_IRUSR | S_IWUSR);
if(fd > 0) { break; }
usleep(100000);
}
if (ftruncate(fd, sizeof(wifibroadcast_rx_status_t)) == -1) {
perror("ftruncate");
exit(1);
}
void *retval = mmap(NULL, sizeof(wifibroadcast_rx_status_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (retval == MAP_FAILED) {
perror("mmap");
exit(1);
}
return (wifibroadcast_rx_status_t*)retval;
}
int main(int argc, char *argv[]) {
int packets1 = 0;
int packets2 = 0;
wifibroadcast_rx_status_t *t = status_memory_open();
packets1 = t->received_packet_cnt;
usleep(900000);
packets2 = t->received_packet_cnt;
// printf("Packets1:%d, Packets2:%d\n",packets1,packets2);
if (packets1 == packets2) {
printf("0\n");
} else {
printf("1\n");
}
return 0;
}