aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-28 17:04:36 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-28 17:04:36 +0100
commitd5ce1a1c62464313ecf3fdc5302c1c3b2c707a37 (patch)
tree6b7457cbdd4b431003dc806d2bd229ff7e417718
parent25483e9c3520ee6922af0682d0f01656a2a8f4a2 (diff)
downloadDns-d5ce1a1c62464313ecf3fdc5302c1c3b2c707a37.zip
Dns-d5ce1a1c62464313ecf3fdc5302c1c3b2c707a37.tar.gz
Dns-d5ce1a1c62464313ecf3fdc5302c1c3b2c707a37.tar.bz2
Answer does no longer force A and IN.
We use $_type and $_class from the question message in the answer message. We also add annotations and use pack() for readibility.
-rw-r--r--Dns.php55
1 files changed, 32 insertions, 23 deletions
diff --git a/Dns.php b/Dns.php
index a924658..61e8d9e 100644
--- a/Dns.php
+++ b/Dns.php
@@ -249,37 +249,46 @@ class Dns implements \Hoa\Core\Event\Listenable {
$i += $length;
}
- $i += 2;
- $type = array_search(
- $_ = (int) (string) ord($handle[$i]) +
- (int) (string) ord($handle[$i + 1]),
- static::$_types
- ) ?: $_;
-
- $i += 2;
- $class = array_search(
- $_ = (int) (string) ord($handle[$i]),
- static::$_classes
- ) ?: $_;
-
- $ips = $this->_on->fire('query', new \Hoa\Core\Event\Bucket(array(
+ $i += 2;
+ $_type = (int) (string) ord($handle[$i]) +
+ (int) (string) ord($handle[$i + 1]);
+ $type = array_search($_type, static::$_types) ?: $_type;
+
+ $i += 2;
+ $_class = (int) (string) ord($handle[$i]);
+ $class = array_search($_class, static::$_classes) ?: $_class;
+
+ $ips = $this->_on->fire('query', new \Hoa\Core\Event\Bucket(array(
'domain' => $domain,
'type' => $type,
'class' => $class
)));
- $ip = null;
+ $ip = null;
foreach(explode('.', $ips[0]) as $foo)
- $ip .= chr($foo);
+ $ip .= pack('C', $foo);
$this->_server->writeAll(
- $buffer[0] . $buffer[1] . chr(129) . chr(128) .
- $buffer[4] . $buffer[5] . $buffer[4] . $buffer[5] .
- chr(0) . chr(0) . chr(0) . chr(0) .
- $handle . chr(192) . chr(12) . chr(0) .
- chr(1) . chr(0) . chr(1) . chr(0) .
- chr(0) . chr(0) . chr(60) . chr(0) .
- chr(4) . $ip
+ $buffer[0] .
+ $buffer[1] .
+ pack('CC', 129, 128) .
+ $buffer[4] .
+ $buffer[5] .
+ $buffer[4] .
+ $buffer[5] .
+ pack('CCCC', 0, 0, 0, 0) .
+ $handle .
+ pack('CC', 192, 12) .
+ // TYPE.
+ pack('n', $_type) .
+ // CLASS.
+ pack('n', $_class) .
+ // TTL.
+ pack('N', 60) .
+ // RDLENGTH.
+ pack('n', 4) .
+ // RDATA.
+ $ip
);
}