@@ -228,6 +228,52 @@ public function testParseResponseWithTwoAnswers()
228228 $ this ->assertSame ('193.223.78.152 ' , $ response ->answers [1 ]->data );
229229 }
230230
231+ public function testParsePTRResponse ()
232+ {
233+ $ data = "" ;
234+ $ data .= "5d d8 81 80 00 01 00 01 00 00 00 00 " ; // header
235+ $ data .= "01 34 01 34 01 38 01 38 07 69 6e " ; // question: 4.4.8.8.in-addr.arpa
236+ $ data .= "2d 61 64 64 72 04 61 72 70 61 00 " ; // question (continued)
237+ $ data .= "00 0c 00 01 " ; // question: type PTR, class IN
238+ $ data .= "c0 0c " ; // answer: offset pointer to rdata
239+ $ data .= "00 0c 00 01 " ; // answer: type PTR, class IN
240+ $ data .= "00 01 51 7f " ; // answer: ttl 86399
241+ $ data .= "00 20 " ; // answer: rdlength 32
242+ $ data .= "13 67 6f 6f 67 6c 65 2d 70 75 62 6c 69 63 2d 64 " ; // answer: rdata google-public-dns-b.google.com.
243+ $ data .= "6e 73 2d 62 06 67 6f 6f 67 6c 65 03 63 6f 6d 00 " ;
244+
245+ $ data = $ this ->convertTcpDumpToBinary ($ data );
246+
247+ $ response = $ this ->parser ->parseMessage ($ data );
248+
249+ $ header = $ response ->header ;
250+ $ this ->assertSame (0x5dd8 , $ header ->get ('id ' ));
251+ $ this ->assertSame (1 , $ header ->get ('qdCount ' ));
252+ $ this ->assertSame (1 , $ header ->get ('anCount ' ));
253+ $ this ->assertSame (0 , $ header ->get ('nsCount ' ));
254+ $ this ->assertSame (0 , $ header ->get ('arCount ' ));
255+ $ this ->assertSame (1 , $ header ->get ('qr ' ));
256+ $ this ->assertSame (Message::OPCODE_QUERY , $ header ->get ('opcode ' ));
257+ $ this ->assertSame (0 , $ header ->get ('aa ' ));
258+ $ this ->assertSame (0 , $ header ->get ('tc ' ));
259+ $ this ->assertSame (1 , $ header ->get ('rd ' ));
260+ $ this ->assertSame (1 , $ header ->get ('ra ' ));
261+ $ this ->assertSame (0 , $ header ->get ('z ' ));
262+ $ this ->assertSame (Message::RCODE_OK , $ header ->get ('rcode ' ));
263+
264+ $ this ->assertCount (1 , $ response ->questions );
265+ $ this ->assertSame ('4.4.8.8.in-addr.arpa ' , $ response ->questions [0 ]['name ' ]);
266+ $ this ->assertSame (Message::TYPE_PTR , $ response ->questions [0 ]['type ' ]);
267+ $ this ->assertSame (Message::CLASS_IN , $ response ->questions [0 ]['class ' ]);
268+
269+ $ this ->assertCount (1 , $ response ->answers );
270+ $ this ->assertSame ('4.4.8.8.in-addr.arpa ' , $ response ->answers [0 ]->name );
271+ $ this ->assertSame (Message::TYPE_PTR , $ response ->answers [0 ]->type );
272+ $ this ->assertSame (Message::CLASS_IN , $ response ->answers [0 ]->class );
273+ $ this ->assertSame (86399 , $ response ->answers [0 ]->ttl );
274+ $ this ->assertSame ('google-public-dns-b.google.com ' , $ response ->answers [0 ]->data );
275+ }
276+
231277 /**
232278 * @expectedException InvalidArgumentException
233279 */
0 commit comments