Exemplo n.º 1
0
 function read($buf)
 {
     $this->buffer .= $buf;
     $ans = new Net_DNS_Packet();
     if ($ans->parse($this->buffer)) {
         if ($ans->header->qr != '1') {
             $this->result(AsyncDNS::RES_ERROR, "Not an answer");
         } else {
             if ($ans->header->id != $this->packet->header->id) {
                 $this->result(AsyncDNS::RES_ERROR, "Invalid ID");
             }
         }
         if ($ans->header->ancount <= 0) {
             if ($ans->header->rcode === 'FORMERR') {
                 $this->result(AsyncDNS::RES_ERROR, "FormERR!?");
                 return;
             } else {
                 $this->result(AsyncDNS::RES_NOTFOUND, $ans);
             }
         } else {
             $this->result(AsyncDNS::RES_FOUND, $ans);
         }
     }
     // unparseable, but maybe next time?
 }
 /**
  * Requests the next RR from a existing transfer started with axfr_start
  *
  * @return object Net_DNS_RR Returns a Net_DNS_RR object of the next RR
  *                           from a zone transfer.
  * @see Net_DNS_Resolver::send_tcp()
  */
 function axfr_next()
 {
     if (!count($this->_axfr_rr)) {
         if (!isset($this->_axfr_sock) || !is_resource($this->_axfr_sock)) {
             $this->errorstring = 'no zone transfer in progress';
             return NULL;
         }
         $timeout = $this->tcp_timeout;
         $buf = $this->read_tcp($this->_axfr_sock, 2, $this->debug);
         if (!strlen($buf)) {
             $this->errorstring = 'truncated zone transfer';
             return NULL;
         }
         $len = unpack('n1len', $buf);
         $len = $len['len'];
         if (!$len) {
             $this->errorstring = 'truncated zone transfer';
             return NULL;
         }
         $buf = $this->read_tcp($this->_axfr_sock, $len, $this->debug);
         if ($this->debug) {
             echo ';; received ' . strlen($buf) . "bytes\n";
         }
         if (strlen($buf) != $len) {
             $this->errorstring = 'expected ' . $len . ' bytes, received ' . strlen($buf);
             if ($this->debug) {
                 echo ';; ' . $err . "\n";
             }
             return NULL;
         }
         $ans = new Net_DNS_Packet($this->debug);
         if (!$ans->parse($buf)) {
             if (!$this->errorstring) {
                 $this->errorstring = 'unknown error during packet parsing';
             }
             return NULL;
         }
         if ($ans->header->ancount < 1) {
             $this->errorstring = 'truncated zone transfer';
             return NULL;
         }
         if ($ans->header->rcode != 'NOERROR') {
             $this->errorstring = 'errorcode ' . $ans->header->rcode . ' returned';
             return NULL;
         }
         foreach ($ans->answer as $rr) {
             if ($rr->type == 'SOA') {
                 if (++$this->_axfr_soa_count < 2) {
                     array_push($this->_axfr_rr, $rr);
                 }
             } else {
                 array_push($this->_axfr_rr, $rr);
             }
         }
         if ($this->_axfr_soa_count >= 2) {
             unset($this->_axfr_sock);
         }
     }
     $rr = array_shift($this->_axfr_rr);
     return $rr;
 }