-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBroadcast.h
64 lines (51 loc) · 1.26 KB
/
Broadcast.h
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
//
// Created by Michał Wilczyński on 6/7/18.
//
#ifndef TIN_BROADCAST_H
#define TIN_BROADCAST_H
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <set>
#include <list>
#include <numeric>
#include <chrono>
#include <mutex>
#include <ctime>
#include <stdio.h>
#include <string.h>
class Broadcast {
int sockfd;
struct sockaddr_in their_addr; // connector's address information
struct hostent *he;
int numbytes;
int broadcast = 1;
std::mutex mtx;
struct addrEntry {
std::chrono::system_clock::time_point time_;
sockaddr_in addr_;
addrEntry(std::chrono::system_clock::time_point time, sockaddr_in addr) : time_(time), addr_(addr) {}
bool operator==(const addrEntry& lhs)
{
if (memcmp(&lhs.addr_,&addr_, sizeof(sockaddr_in)) == 0) {
return true;
}
else {
return false;
}
}
};
std::list<addrEntry> neighbors;
void addNeighbor(sockaddr_in);
public:
void sendDiscoverPacket();
void listenForDiscoverPackets();
};
#endif //TIN_BROADCAST_H