-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ping.h
41 lines (30 loc) · 877 Bytes
/
Ping.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
#ifndef PING_H
#define PING_H
#include <arpa/inet.h>
#include <netinet/ip_icmp.h>
#include <sys/types.h>
#include <string>
#include <unistd.h>
#include <iostream>
#define MAX_IPV4_PACKET_SIZE 65535 // Maximum size of IPV4 packet (bytes)
#define MAX_IPV4_HEADER_SIZE 60 // Maximum size of IPV4 header (bytes)
// Maximum size of the ICMP data
#define MAX_ICMP_DATA_SIZE (MAX_IPV4_PACKET_SIZE - MAX_IPV4_HEADER_SIZE - ICMP_MINLEN)
#define SOCK_DOMAIN AF_INET
#define SOCK_TYPE SOCK_RAW
#define SOCK_PROTOCOL IPPROTO_ICMP
using namespace std;
class Ping {
public:
Ping();
Ping(string);
Ping(const Ping& orig);
void startPinging();
virtual ~Ping();
private:
int sockFd = socket(SOCK_DOMAIN, SOCK_TYPE, SOCK_PROTOCOL);
string ip;
struct sockaddr_in sendTo;
void initSendToSockAddr();
};
#endif /* PING_H */