aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-28 18:35:10 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-28 18:35:10 +0100
commit3b5341b9654b68a0ff563f5f4e6d2509d9b4ed82 (patch)
tree1572fcd7b55b5178e3c2bb3b4cf0a2ef6c94ba4b
parent3d9f85be1c91fdfd3d085983b18641f612217e5a (diff)
downloadDns-3b5341b9654b68a0ff563f5f4e6d2509d9b4ed82.zip
Dns-3b5341b9654b68a0ff563f5f4e6d2509d9b4ed82.tar.gz
Dns-3b5341b9654b68a0ff563f5f4e6d2509d9b4ed82.tar.bz2
Refactor code. Be more explicit.
-rw-r--r--Dns.php37
1 files changed, 31 insertions, 6 deletions
diff --git a/Dns.php b/Dns.php
index c316b25..aa8267d 100644
--- a/Dns.php
+++ b/Dns.php
@@ -220,8 +220,9 @@ class Dns implements \Hoa\Core\Event\Listenable {
if(empty($buffer))
continue;
- $domain = null;
+ // Skip header.
$handle = substr($buffer, 12);
+ $domain = null;
// QNAME.
for($i = 0, $m = strlen($handle); $i < $m; ++$i) {
@@ -258,16 +259,40 @@ class Dns implements \Hoa\Core\Event\Listenable {
$ip .= pack('C', $foo);
$this->_server->writeAll(
+ // Header.
+
+ // ID.
$buffer[0] .
$buffer[1] .
- pack('CC', 129, 128) .
- $buffer[4] .
- $buffer[5] .
+ pack(
+ 'C',
+ 1 << 7 // QR, 1 = response.
+ // OpCode, 0 = QUERY.
+ // AA, 0
+ // TC, 0
+ | 1 // RD
+ ) .
+ pack(
+ 'C',
+ 0 // RA, Z, AD, CD.
+ ) .
+ // QDCOUNT.
$buffer[4] .
$buffer[5] .
- pack('CCCC', 0, 0, 0, 0) .
- $handle .
+ // ANCOUNT.
+ pack('n', 1) .
+ // NSCOUNT.
+ pack('n', 0) .
+ // ARCOUNT.
+ pack('n', 0) .
+
+ // Question.
+
+ $handle .
pack('CC', 192, 12) .
+
+ // Answer.
+
// TYPE.
pack('n', $_type) .
// CLASS.