Skip to content

Commit 4d70ed6

Browse files
akondasclue
authored andcommitted
Implement SPF dns record type
1 parent 92a1727 commit 4d70ed6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/Model/Message.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final class Message
3434
* The OPT record uses the "ttl" field to store additional flags.
3535
*/
3636
const TYPE_OPT = 41;
37+
const TYPE_SPF = 99; // Sender Policy Framework (SPF) - https://tools.ietf.org/html/rfc4408#section-3.1.1
3738
const TYPE_ANY = 255;
3839
const TYPE_CAA = 257;
3940

src/Protocol/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private function parseRecord(Message $message)
171171
}
172172
} elseif (Message::TYPE_CNAME === $type || Message::TYPE_PTR === $type || Message::TYPE_NS === $type) {
173173
list($rdata, $consumed) = $this->readDomain($message->data, $consumed);
174-
} elseif (Message::TYPE_TXT === $type) {
174+
} elseif (Message::TYPE_TXT === $type || Message::TYPE_SPF === $type) {
175175
$rdata = array();
176176
while ($consumed < $expected) {
177177
$len = ord($message->data[$consumed]);

tests/Protocol/ParserTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,25 @@ public function testParseTXTResponse()
305305
$this->assertSame(array('hello'), $response->answers[0]->data);
306306
}
307307

308+
public function testParseSPFResponse()
309+
{
310+
$data = "";
311+
$data .= "04 69 67 6f 72 02 69 6f 00"; // answer: igor.io
312+
$data .= "00 63 00 01"; // answer: type SPF, class IN
313+
$data .= "00 01 51 80"; // answer: ttl 86400
314+
$data .= "00 06"; // answer: rdlength 6
315+
$data .= "05 68 65 6c 6c 6f"; // answer: rdata length 5: hello
316+
317+
$response = $this->parseAnswer($data);
318+
319+
$this->assertCount(1, $response->answers);
320+
$this->assertSame('igor.io', $response->answers[0]->name);
321+
$this->assertSame(Message::TYPE_SPF, $response->answers[0]->type);
322+
$this->assertSame(Message::CLASS_IN, $response->answers[0]->class);
323+
$this->assertSame(86400, $response->answers[0]->ttl);
324+
$this->assertSame(array('hello'), $response->answers[0]->data);
325+
}
326+
308327
public function testParseTXTResponseMultiple()
309328
{
310329
$data = "";

0 commit comments

Comments
 (0)