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