1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Badcow DNS Library. |
7
|
|
|
* |
8
|
|
|
* (c) Samuel Williams <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Rdata; |
15
|
|
|
|
16
|
|
|
use Badcow\DNS\Message; |
17
|
|
|
|
18
|
|
|
class AFSDB implements RdataInterface |
19
|
|
|
{ |
20
|
1 |
|
use RdataTrait; |
21
|
|
|
|
22
|
|
|
const TYPE = 'AFSDB'; |
23
|
|
|
const TYPE_CODE = 18; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
private $subType; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $hostname; |
34
|
|
|
|
35
|
1 |
|
public function getSubType(): int |
36
|
|
|
{ |
37
|
1 |
|
return $this->subType; |
38
|
|
|
} |
39
|
|
|
|
40
|
5 |
|
public function setSubType(int $subType): void |
41
|
|
|
{ |
42
|
5 |
|
$this->subType = $subType; |
43
|
5 |
|
} |
44
|
|
|
|
45
|
1 |
|
public function getHostname(): string |
46
|
|
|
{ |
47
|
1 |
|
return $this->hostname; |
48
|
|
|
} |
49
|
|
|
|
50
|
5 |
|
public function setHostname(string $hostname): void |
51
|
|
|
{ |
52
|
5 |
|
$this->hostname = $hostname; |
53
|
5 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws \InvalidArgumentException |
57
|
|
|
*/ |
58
|
4 |
|
public function toText(): string |
59
|
|
|
{ |
60
|
4 |
|
if (!isset($this->subType)) { |
61
|
1 |
|
throw new \InvalidArgumentException('No sub-type has been set on AFSDB object.'); |
62
|
|
|
} |
63
|
|
|
|
64
|
3 |
|
if (!isset($this->hostname)) { |
65
|
1 |
|
throw new \InvalidArgumentException('No hostname has been set on AFSDB object.'); |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
return sprintf('%d %s', $this->subType, $this->hostname); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function toWire(): string |
72
|
|
|
{ |
73
|
1 |
|
return pack('n', $this->subType).Message::encodeName($this->hostname); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function fromText(string $text): void |
77
|
|
|
{ |
78
|
1 |
|
$rdata = explode(' ', $text); |
79
|
|
|
|
80
|
1 |
|
$this->setSubType((int) $rdata[0]); |
81
|
1 |
|
$this->setHostname($rdata[1]); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
1 |
|
public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void |
85
|
|
|
{ |
86
|
1 |
|
if (false === $subType = unpack('n', $rdata, $offset)) { |
87
|
1 |
|
throw new DecodeException(static::TYPE, $rdata); |
88
|
1 |
|
} |
89
|
1 |
|
$this->setSubType($subType[1]); |
90
|
|
|
$offset += 2; |
91
|
|
|
$this->setHostname(Message::decodeName($rdata, $offset)); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|