tracertquery.h
2.47 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
//
// traceroutequery.h
// BBAAPIRequest_Sdt
//
// Created by chenjia09 on 2019/9/16.
//
#ifndef SDT_SRC_ACTIVECHECK_TRACERTQUERY_H_
#define SDT_SRC_ACTIVECHECK_TRACERTQUERY_H_
#include <string>
#include <vector>
#include <sys/socket.h>
#include <netinet/in.h>
class NetCheckTrafficMonitor;
#define DISALLOW_COPY_AND_ASSIGN(cls) \
private:\
cls(const cls&); \
cls& operator=(const cls&);
namespace apirequest {
namespace sdt {
struct TracertRecord {
std::vector<double> durations;
int ttl; // ms
char ip[16];
};
struct TracertResult {
std::string res;
std::vector<struct TracertRecord> records;
int totaljumps;
std::string dest_ip;
};
class TracertQuery {
public:
TracertQuery(): tracertresult_("")
#ifdef __APPLE__
, nsent_(0),
sockfd_(-1),
readcount_(0),
timeout_(0),
maxjumps_(0),
currentttl_(1)
#endif
{}
~TracertQuery() {
}
public:
/**
* return value:
* 0---->success
* -1--->error
*/
int GetTracertResult(struct TracertResult& tracertResult);
/**
* return value:
* 0---->success
* -1--->error
*/
int RunTracertQuery(int _querycount, int _interval/*S*/, int _timeout/*S*/, int _maxjumps, const char* _dest, unsigned int _packet_size = 0);
#ifdef __APPLE__
private:
void proc_v4(char* _ptr, ssize_t _len, struct sockaddr_in* _remoteAddr, struct timeval* _tvrecv);
void proc_v6(char* _ptr, ssize_t _len, struct sockaddr_in6* _remoteAddr, struct timeval* _tvrecv);
int __prepareSendAddr(const char* dest);
int __runReadWrite(bool isIPv6);
void __onAlarm();
void __preparePacket(char* sendbuffer, int& len, bool isIPv6);
int __send(bool isIPv6);
int __recv(bool isIPv6);
int __initialize(const char* dest);
void __deinitialize();
#endif
DISALLOW_COPY_AND_ASSIGN(TracertQuery);
private:
std::string tracertresult_;
#ifdef __APPLE__
int nsent_; /* add 1 for each sendto() */
int sockfd_;
int readcount_;
int timeout_;
int maxjumps_;
int currentttl_;
struct TracertRecord currentRecord_;
struct timeval sendstamp_;
std::vector<struct TracertRecord> records_;
struct sockaddr sendaddr_;
struct sockaddr_in6 sendaddr6_;
#endif
};
}}
#endif /* traceroutequery_h */