forked from tomaszmrugalski/dibbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpt.h
113 lines (93 loc) · 2.59 KB
/
Opt.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
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
105
106
107
108
109
110
111
112
113
/*
* Dibbler - a portable DHCPv6
*
* authors: Tomasz Mrugalski <[email protected]>
* Marek Senderski <[email protected]>
*
* released under GNU GPL v2 only licence
*
*/
#ifndef OPT_H
#define OPT_H
#include <stdint.h>
#include <list>
#include "SmartPtr.h"
#include "Container.h"
#include "DUID.h"
class TMsg;
class TOpt;
typedef SPtr<TOpt> TOptPtr;
typedef std::list< TOptPtr > TOptList;
typedef TContainer< TOptPtr > TOptContainer;
class TOpt
{
public:
/// length of a DHCPv6 option header
const static size_t OPTION6_HDR_LEN = 4;
/* this is required to specify, what is the format of expected options.
This cannot be class field or method, because there is no object
to hold that information. Option object is created when requested
option is received. */
typedef enum {
Layout_Addr,
Layout_AddrLst,
Layout_String,
Layout_StringLst,
Layout_Duid,
Layout_Generic
} EOptionLayout;
TOpt(int optType, TMsg* parent);
virtual ~TOpt();
/**
* Return the size of the option, including :
* - Option number,
* - Option size
* - data
*
* @return the size
*/
virtual size_t getSize() = 0;
/**
* This method transform the instance of the option class into bytecode
* ready to be sent to the client or server, conform to the RFC
*
* @param buf The address where to store the option
* @return The address where the option ends
*/
virtual char * storeSelf(char* buf) = 0;
virtual bool doDuties() = 0;
/**
* Validate the option
*
* @return true if the option is valid.
*/
virtual bool isValid() const;
virtual std::string getPlain();
int getOptType();
TOptPtr getOption(int type);
// suboptions management
void firstOption();
TOptPtr getOption();
void addOption(TOptPtr opt);
bool delOption(uint16_t type);
int countOption();
void delAllOptions();
void setParent(TMsg* Parent);
static bool parseOptions(TOptContainer& options,
const char* buf,
size_t len,
TMsg* parent,
uint16_t placeId = 0, // 5 (option 5) or (message 5)
std::string place = "option" // "option" or "message"
);
static TOptPtr getOption(const TOptList& list, uint16_t opt_type);
protected:
char* storeHeader(char* buf);
char* storeSubOpt(char* buf);
int getSubOptSize();
TOptContainer SubOptions;
int OptType;
TMsg* Parent;
bool Valid;
};
#endif