function error() { if ($this->error != 0) { $rcode = Net_DNS::rcodesbyval($error); } return $rcode; }
/** * Initializes the default values for the Header object. * * Builds a header object from either default values, or from a DNS * packet passed into the constructor as $data * * @param string $data A DNS packet of which the header will be parsed. * @return object Net_DNS_Header * @access public */ function Net_DNS_Header($data = '') { if ($data != '') { /* * The header MUST be at least 12 bytes. * Passing the full datagram to this constructor * will examine only the header section of the DNS packet */ if (strlen($data) < 12) { return false; } $a = unpack('nid/C2flags/n4counts', $data); $this->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); } }