-
Notifications
You must be signed in to change notification settings - Fork 1
/
dtls.h
56 lines (52 loc) · 1.2 KB
/
dtls.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
#ifndef DTLS_H
#define DTLS_H
class cDtlsHeader {
public:
#pragma pack(push, 1)
struct sFixHeader {
u_int8_t content_type;
u_int16_t version;
u_int16_t epoch;
u_int16_t sequence_number_filler;
u_int32_t sequence_number;
u_int16_t length;
};
#pragma pack(pop)
public:
cDtlsHeader(char *header, unsigned limitSize) {
this->header = (u_char*)header;
this->limitSize = limitSize;
}
cDtlsHeader(u_char *header, unsigned limitSize) {
this->header = header;
this->limitSize = limitSize;
}
sFixHeader getFixHeader() {
sFixHeader fixHeader = *(sFixHeader*)header;
fixHeader.version = htons(fixHeader.version);
fixHeader.epoch = htons(fixHeader.epoch);
fixHeader.sequence_number = htonl(fixHeader.sequence_number);
fixHeader.length = htons(fixHeader.length);
return(fixHeader);
}
unsigned getHeaderSize() {
return(sizeof(sFixHeader));
}
unsigned getLength() {
return(htons(((sFixHeader*)header)->length));
}
bool isOkHeaderSize() {
return(limitSize >= getHeaderSize());
}
bool isOkLength() {
return(limitSize >= getHeaderSize() + getLength());
}
bool isOk() {
return(isOkHeaderSize() &&
isOkLength());
}
public:
u_char *header;
unsigned limitSize;
};
#endif //DTLS_H