function data($packet, $offset) { $data = $packet->dn_comp($this->qname, $offset); $data .= pack('n', Net_DNS::typesbyname(strtoupper($this->qtype))); $data .= pack('n', Net_DNS::classesbyname(strtoupper($this->qclass))); return $data; }
/** * Parses a resource record section of a packet * * Examines a DNS packet at the specified offset and parses the data * of a section which contains RRs (ANSWER, AUTHORITY, ADDITIONAL). * * @param string $data The packet data returned from the server * @param integer $offset The location offset of the start of the resource * record section. * @return array An array of type array($rr, $offset) where $rr * is a Net_DNS_RR object and $offset is the * location of the next section of the packet which * needs to be parsed. */ function parse_rr($data, $offset) { list($name, $offset) = $this->dn_expand($data, $offset); if ($name === null) { return array(null, null); } if (strlen($data) < $offset + 10) { return array(null, null); } $a = unpack("@{$offset}/n2tc/Nttl/nrdlength", $data); $type = $a['tc1']; $class = $a['tc2']; $ttl = $a['ttl']; $rdlength = $a['rdlength']; $type = Net_DNS::typesbyval($type); $class = Net_DNS::classesbyval($class); $offset += 10; if (strlen($data) < $offset + $rdlength) { return array(null, null); } $rrobj =& Net_DNS_RR::factory(array($name, $type, $class, $ttl, $rdlength, $data, $offset)); if (is_null($rrobj)) { return array(null, null); } $offset += $rdlength; return array($rrobj, $offset); }
function data(&$packet, $offset) { $data = $packet->dn_comp($this->name, $offset); $data .= pack('n', Net_DNS::typesbyname(strtoupper($this->type))); $data .= pack('n', Net_DNS::classesbyname(strtoupper($this->class))); $data .= pack('N', $this->ttl); $offset += strlen($data) + 2; // The 2 extra bytes are for rdlength $rdata = $this->rdata($packet, $offset); $data .= pack('n', strlen($rdata)); $data .= $rdata; return $data; }
function error() { if ($this->error != 0) { $rcode = Net_DNS::rcodesbyval($error); } return $rcode; }
/** * Returns the binary data containing the properties of the header * * Packs the properties of the Header object into a binary string * suitable for using as the Header section of a DNS packet. * * @return string binary representation of the header object * @access public */ function data() { $opcode = Net_DNS::opcodesbyname($this->opcode); $rcode = Net_DNS::rcodesbyname($this->rcode); $byte2 = $this->qr << 7 | $opcode << 3 | $this->aa << 2 | $this->tc << 1 | $this->rd; $byte3 = $this->ra << 7 | $rcode; return pack('nC2n4', $this->id, $byte2, $byte3, $this->qdcount, $this->ancount, $this->nscount, $this->arcount); }