function &factory($rrdata, $update_type = '') { if (is_string($rrdata)) { $rr =& Net_DNS_RR::new_from_string($rrdata, $update_type); } elseif (count($rrdata) == 7) { list($name, $rrtype, $rrclass, $ttl, $rdlength, $data, $offset) = $rrdata; $rr =& Net_DNS_RR::new_from_data($name, $rrtype, $rrclass, $ttl, $rdlength, $data, $offset); } else { $rr =& Net_DNS_RR::new_from_array($rrdata); } return $rr; }
/** * 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); }