id = $a['id']; $this->qr = ($a['flags1'] >> 7) & 0x1; $this->opcode = ($a['flags1'] >> 3) & 0xf; $this->aa = ($a['flags1'] >> 2) & 0x1; $this->tc = ($a['flags1'] >> 1) & 0x1; $this->rd = $a['flags1'] & 0x1; $this->ra = ($a['flags2'] >> 7) & 0x1; $this->rcode = $a['flags2'] & 0xf; $this->qdcount = $a['counts1']; $this->ancount = $a['counts2']; $this->nscount = $a['counts3']; $this->arcount = $a['counts4']; } else { $this->id = Net_DNS_Resolver::nextid(); $this->qr = 0; $this->opcode = 0; $this->aa = 0; $this->tc = 0; $this->rd = 1; $this->ra = 0; $this->rcode = 0; $this->qdcount = 1; $this->ancount = 0; $this->nscount = 0; $this->arcount = 0; } if (Net_DNS::opcodesbyval($this->opcode)) { $this->opcode = Net_DNS::opcodesbyval($this->opcode); } if (Net_DNS::rcodesbyval($this->rcode)) { $this->rcode = Net_DNS::rcodesbyval($this->rcode); } } /* }}} */ /* Net_DNS_Header::display() {{{ */ /** * Displays the properties of the header. * * Displays the properties of the header. * * @access public */ function display() { echo $this->string(); } /* }}} */ /* Net_DNS_Header::string() {{{ */ /** * Returns a formatted string containing the properties of the header. * * @return string a formatted string containing the properties of the header. * @access public */ function string() { $retval = ';; id = ' . $this->id . "\n"; if ($this->opcode == 'UPDATE') { $retval .= ';; qr = ' . $this->qr . ' ' . 'opcode = ' . $this->opcode . ' ' . 'rcode = ' . $this->rcode . "\n"; $retval .= ';; zocount = ' . $this->qdcount . ' ' . 'prcount = ' . $this->ancount . ' ' . 'upcount = ' . $this->nscount . ' ' . 'adcount = ' . $this->arcount . "\n"; } else { $retval .= ';; qr = ' . $this->qr . ' ' . 'opcode = ' . $this->opcode . ' ' . 'aa = ' . $this->aa . ' ' . 'tc = ' . $this->tc . ' ' . 'rd = ' . $this->rd . "\n"; $retval .= ';; ra = ' . $this->ra . ' ' . 'rcode = ' . $this->rcode . "\n"; $retval .= ';; qdcount = ' . $this->qdcount . ' ' . 'ancount = ' . $this->ancount . ' ' . 'nscount = ' . $this->nscount . ' ' . 'arcount = ' . $this->arcount . "\n"; } return($retval); } /* }}} */ /* Net_DNS_Header::data() {{{ */ /** * 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); } /* }}} */ } /* }}} */ /* VIM settings {{{ * Local variables: * tab-width: 4 * c-basic-offset: 4 * soft-stop-width: 4 * c indent on * expandtab on * End: * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et * vim<600: sw=4 ts=4 * }}} */ ?>