Skip to content

Commit 9c8225e

Browse files
authored
Merge pull request #58 from othillo/aaaa
support AAAA
2 parents e09ca28 + 79361e9 commit 9c8225e

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/Model/Message.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Message
1414
const TYPE_PTR = 12;
1515
const TYPE_MX = 15;
1616
const TYPE_TXT = 16;
17+
const TYPE_AAAA = 28;
1718

1819
const CLASS_IN = 1;
1920

src/Protocol/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function parseAnswer(Message $message)
159159

160160
$rdata = null;
161161

162-
if (Message::TYPE_A === $type) {
162+
if (Message::TYPE_A === $type || Message::TYPE_AAAA === $type) {
163163
$ip = substr($message->data, $consumed, $rdLength);
164164
$consumed += $rdLength;
165165

tests/Protocol/ParserTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,50 @@ public function testParseResponseWithCnameAndOffsetPointers()
186186
$this->assertSame('googlemail.l.google.com', $response->answers[0]->data);
187187
}
188188

189+
public function testParseAAAAResponse()
190+
{
191+
$data = "";
192+
$data .= "cd 72 81 80 00 01 00 01 00 00 00 00 06"; // header
193+
$data .= "67 6f 6f 67 6c 65 03 63 6f 6d 00"; // question: google.com
194+
$data .= "00 1c 00 01"; // question: type AAAA, class IN
195+
$data .= "c0 0c"; // answer: offset pointer to google.com
196+
$data .= "00 1c 00 01"; // answer: type AAAA, class IN
197+
$data .= "00 00 01 2b"; // answer: ttl 299
198+
$data .= "00 10"; // answer: rdlength 16
199+
$data .= "2a 00 14 50 40 09 08 09 00 00 00 00 00 00 20 0e"; // answer: 2a00:1450:4009:809::200e
200+
201+
$data = $this->convertTcpDumpToBinary($data);
202+
203+
$response = $this->parser->parseMessage($data);
204+
205+
$header = $response->header;
206+
$this->assertSame(0xcd72, $header->get('id'));
207+
$this->assertSame(1, $header->get('qdCount'));
208+
$this->assertSame(1, $header->get('anCount'));
209+
$this->assertSame(0, $header->get('nsCount'));
210+
$this->assertSame(0, $header->get('arCount'));
211+
$this->assertSame(1, $header->get('qr'));
212+
$this->assertSame(Message::OPCODE_QUERY, $header->get('opcode'));
213+
$this->assertSame(0, $header->get('aa'));
214+
$this->assertSame(0, $header->get('tc'));
215+
$this->assertSame(1, $header->get('rd'));
216+
$this->assertSame(1, $header->get('ra'));
217+
$this->assertSame(0, $header->get('z'));
218+
$this->assertSame(Message::RCODE_OK, $header->get('rcode'));
219+
220+
$this->assertCount(1, $response->questions);
221+
$this->assertSame('google.com', $response->questions[0]['name']);
222+
$this->assertSame(Message::TYPE_AAAA, $response->questions[0]['type']);
223+
$this->assertSame(Message::CLASS_IN, $response->questions[0]['class']);
224+
225+
$this->assertCount(1, $response->answers);
226+
$this->assertSame('google.com', $response->answers[0]->name);
227+
$this->assertSame(Message::TYPE_AAAA, $response->answers[0]->type);
228+
$this->assertSame(Message::CLASS_IN, $response->answers[0]->class);
229+
$this->assertSame(299, $response->answers[0]->ttl);
230+
$this->assertSame('2a00:1450:4009:809::200e', $response->answers[0]->data);
231+
}
232+
189233
public function testParseResponseWithTwoAnswers()
190234
{
191235
$data = "";

0 commit comments

Comments
 (0)