1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of PHP DNS Server. |
4
|
|
|
* |
5
|
|
|
* (c) Yif Swery <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace yswery\DNS; |
12
|
|
|
|
13
|
|
|
class Header |
14
|
|
|
{ |
15
|
|
|
const OPCODE_STANDARD_QUERY = 0; |
16
|
|
|
|
17
|
|
|
const OPCODE_INVERSE_QUERY = 1; |
18
|
|
|
|
19
|
|
|
const OPCODE_STATUS_REQUEST = 2; |
20
|
|
|
|
21
|
|
|
const RCODE_NO_ERROR = 0; |
22
|
|
|
|
23
|
|
|
const RCODE_FORMAT_ERROR = 1; |
24
|
|
|
|
25
|
|
|
const RCODE_SERVER_FAILURE = 2; |
26
|
|
|
|
27
|
|
|
const RCODE_NAME_ERROR = 3; |
28
|
|
|
|
29
|
|
|
const RCODE_NOT_IMPLEMENTED = 4; |
30
|
|
|
|
31
|
|
|
const RCODE_REFUSED = 5; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* ID. |
35
|
|
|
* |
36
|
|
|
* @var int |
37
|
|
|
*/ |
38
|
|
|
private $id; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* QR. |
42
|
|
|
* |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
private $response; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* OPCODE. |
49
|
|
|
* |
50
|
|
|
* @var int |
51
|
|
|
*/ |
52
|
|
|
private $opcode; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* AA. |
56
|
|
|
* |
57
|
|
|
* @var bool |
58
|
|
|
*/ |
59
|
|
|
private $authoritative; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* TC. |
63
|
|
|
* |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
private $truncated; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* RD. |
70
|
|
|
* |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
private $recursionDesired; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* RA. |
77
|
|
|
* |
78
|
|
|
* @var bool |
79
|
|
|
*/ |
80
|
|
|
private $recursionAvailable; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* A. |
84
|
|
|
* |
85
|
|
|
* @var int |
86
|
|
|
*/ |
87
|
|
|
private $z = 0; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* RCODE. |
91
|
|
|
* |
92
|
|
|
* @var int |
93
|
|
|
*/ |
94
|
|
|
private $rcode; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* QDCOUNT. |
98
|
|
|
* |
99
|
|
|
* @var int |
100
|
|
|
*/ |
101
|
|
|
private $questionCount; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* ANCOUNT. |
105
|
|
|
* |
106
|
|
|
* @var int |
107
|
|
|
*/ |
108
|
|
|
private $answerCount; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* NSCOUNT. |
112
|
|
|
* |
113
|
|
|
* @var int |
114
|
|
|
*/ |
115
|
|
|
private $nameServerCount; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* ARCOUNT. |
119
|
|
|
* |
120
|
|
|
* @var int |
121
|
|
|
*/ |
122
|
|
|
private $additionalRecordsCount; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return int |
126
|
|
|
*/ |
127
|
|
|
public function getId() |
128
|
|
|
{ |
129
|
|
|
return $this->id; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param $id |
134
|
|
|
* |
135
|
|
|
* @return $this |
136
|
|
|
*/ |
137
|
|
|
public function setId($id) |
138
|
|
|
{ |
139
|
|
|
$this->id = (int) $id; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return bool |
146
|
|
|
*/ |
147
|
|
|
public function isQuery() |
148
|
|
|
{ |
149
|
|
|
return !$this->response; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return bool |
154
|
|
|
*/ |
155
|
|
|
public function isResponse() |
156
|
|
|
{ |
157
|
|
|
return $this->response; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param $response |
162
|
|
|
* |
163
|
|
|
* @return $this |
164
|
|
|
*/ |
165
|
|
|
public function setResponse($response) |
166
|
|
|
{ |
167
|
|
|
$this->response = (bool) $response; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param $query |
174
|
|
|
* |
175
|
|
|
* @return $this |
176
|
|
|
*/ |
177
|
|
|
public function setQuery($query) |
178
|
|
|
{ |
179
|
|
|
$this->response = !((bool) $query); |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return int |
186
|
|
|
*/ |
187
|
|
|
public function getOpcode() |
188
|
|
|
{ |
189
|
|
|
return $this->opcode; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param $opcode |
194
|
|
|
* |
195
|
|
|
* @return $this |
196
|
|
|
*/ |
197
|
|
|
public function setOpcode($opcode) |
198
|
|
|
{ |
199
|
|
|
$this->opcode = (int) $opcode; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return bool |
206
|
|
|
*/ |
207
|
|
|
public function isAuthoritative() |
208
|
|
|
{ |
209
|
|
|
return $this->authoritative; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param $authoritative |
214
|
|
|
* |
215
|
|
|
* @return $this |
216
|
|
|
*/ |
217
|
|
|
public function setAuthoritative($authoritative) |
218
|
|
|
{ |
219
|
|
|
$this->authoritative = (bool) $authoritative; |
220
|
|
|
|
221
|
|
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @return bool |
226
|
|
|
*/ |
227
|
|
|
public function isTruncated() |
228
|
|
|
{ |
229
|
|
|
return $this->truncated; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param $truncated |
234
|
|
|
* |
235
|
|
|
* @return $this |
236
|
|
|
*/ |
237
|
|
|
public function setTruncated($truncated) |
238
|
|
|
{ |
239
|
|
|
$this->truncated = (bool) $truncated; |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @return bool |
246
|
|
|
*/ |
247
|
|
|
public function isRecursionDesired() |
248
|
|
|
{ |
249
|
|
|
return $this->recursionDesired; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @param $recursionDesired |
254
|
|
|
* |
255
|
|
|
* @return $this |
256
|
|
|
*/ |
257
|
|
|
public function setRecursionDesired($recursionDesired) |
258
|
|
|
{ |
259
|
|
|
$this->recursionDesired = (bool) $recursionDesired; |
260
|
|
|
|
261
|
|
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @return bool |
266
|
|
|
*/ |
267
|
|
|
public function isRecursionAvailable() |
268
|
|
|
{ |
269
|
|
|
return $this->recursionAvailable; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param $recursionAvailable |
274
|
|
|
* |
275
|
|
|
* @return $this |
276
|
|
|
*/ |
277
|
|
|
public function setRecursionAvailable($recursionAvailable) |
278
|
|
|
{ |
279
|
|
|
$this->recursionAvailable = (bool) $recursionAvailable; |
280
|
|
|
|
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return int |
286
|
|
|
*/ |
287
|
|
|
public function getZ() |
288
|
|
|
{ |
289
|
|
|
return $this->z; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* @param $z |
294
|
|
|
* |
295
|
|
|
* @return $this |
296
|
|
|
*/ |
297
|
|
|
public function setZ($z) |
298
|
|
|
{ |
299
|
|
|
$this->z = (int) $z; |
300
|
|
|
|
301
|
|
|
return $this; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @return int |
306
|
|
|
*/ |
307
|
|
|
public function getRcode() |
308
|
|
|
{ |
309
|
|
|
return $this->rcode; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @param $rcode |
314
|
|
|
* |
315
|
|
|
* @return $this |
316
|
|
|
*/ |
317
|
|
|
public function setRcode($rcode) |
318
|
|
|
{ |
319
|
|
|
$this->rcode = (int) $rcode; |
320
|
|
|
|
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* @return int |
326
|
|
|
*/ |
327
|
|
|
public function getQuestionCount() |
328
|
|
|
{ |
329
|
|
|
return $this->questionCount; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @param $questionCount |
334
|
|
|
* |
335
|
|
|
* @return $this |
336
|
|
|
*/ |
337
|
|
|
public function setQuestionCount($questionCount) |
338
|
|
|
{ |
339
|
|
|
$this->questionCount = (int) $questionCount; |
340
|
|
|
|
341
|
|
|
return $this; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return int |
346
|
|
|
*/ |
347
|
|
|
public function getAnswerCount() |
348
|
|
|
{ |
349
|
|
|
return $this->answerCount; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @param $answerCount |
354
|
|
|
* |
355
|
|
|
* @return $this |
356
|
|
|
*/ |
357
|
|
|
public function setAnswerCount($answerCount) |
358
|
|
|
{ |
359
|
|
|
$this->answerCount = (int) $answerCount; |
360
|
|
|
|
361
|
|
|
return $this; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @return int |
366
|
|
|
*/ |
367
|
|
|
public function getNameServerCount() |
368
|
|
|
{ |
369
|
|
|
return $this->nameServerCount; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @param $nameServerCount |
374
|
|
|
* |
375
|
|
|
* @return $this |
376
|
|
|
*/ |
377
|
|
|
public function setNameServerCount($nameServerCount) |
378
|
|
|
{ |
379
|
|
|
$this->nameServerCount = (int) $nameServerCount; |
380
|
|
|
|
381
|
|
|
return $this; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @return int |
386
|
|
|
*/ |
387
|
|
|
public function getAdditionalRecordsCount() |
388
|
|
|
{ |
389
|
|
|
return $this->additionalRecordsCount; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @param $additionalRecordsCount |
394
|
|
|
* |
395
|
|
|
* @return $this |
396
|
|
|
*/ |
397
|
|
|
public function setAdditionalRecordsCount($additionalRecordsCount) |
398
|
|
|
{ |
399
|
|
|
$this->additionalRecordsCount = (int) $additionalRecordsCount; |
400
|
|
|
|
401
|
|
|
return $this; |
402
|
|
|
} |
403
|
|
|
} |
404
|
|
|
|