Exemple #1
0
function _checkdnsrr($hostname, $type = 'MX')
{
    global $__PHPRESOLVER_RS;
    static $typemap = array('A' => DNS_RECORDTYPE_A, 'MX' => DNS_RECORDTYPE_MX, 'NS' => DNS_RECORDTYPE_NS, 'SOA' => DNS_RECORDTYPE_SOA, 'PTR' => DNS_RECORDTYPE_PTR, 'CNAME' => DNS_RECORDTYPE_CNAME, 'ANY' => DNS_RECORDTYPE_ANY, 'AAAA' => DNS_RECORDTYPE_AAAA);
    if ($__PHPRESOLVER_RS === false) {
        return false;
    }
    $dnsname =& DNSName::newFromString($hostname);
    if (!isset($typemap[$type])) {
        trigger_error(sprintf("Type '%s' is not supported", $type), E_USER_WARNING);
        return false;
    }
    $rt = $typemap[$type];
    $answer =& $__PHPRESOLVER_RS->sendQuery(new DNSQuery(new DNSRecord($dnsname, $rt)));
    if ($answer === false || empty($answer->rec_answer)) {
        return false;
    }
    return true;
}
Exemple #2
0
function GetMXRR($hostname, &$mxhosts, &$weight)
{
    global $__PHPRESOLVER_RS;
    if (!isset($__PHPRESOLVER_RS)) {
        return false;
    }
    $dnsname =& DNSName::newFromString($hostname);
    $answer =& $__PHPRESOLVER_RS->sendQuery(new DNSQuery(new DNSRecord($dnsname, DNS_RECORDTYPE_MX)));
    if ($answer === false || $answer->rec_answer === false) {
        return false;
    } else {
        $i = count($answer->rec_answer);
        $mxhosts = $weight = array();
        while (--$i >= 0) {
            if ($answer->rec_answer[$i]->type == DNS_RECORDTYPE_MX) {
                $rec =& $answer->rec_answer[$i]->specific_fields;
                $mxhosts[] = substr($rec['exchange']->getCanonicalName(), 0, -1);
                $weight[] = $rec['preference'];
            }
        }
        return true;
    }
}
Exemple #3
0
 function getResourceRecords($nrecs)
 {
     $recs = array();
     while (--$nrecs >= 0) {
         if (($labels = $this->getLabels()) === false) {
             return false;
         }
         if (($buf = $this->readStreamDirectly(10)) === false) {
             return false;
         }
         $info = unpack("ntype/ndclass/Nttl/nrdlength", $buf);
         switch ($info['type']) {
             case DNS_RECORDTYPE_CNAME:
             case DNS_RECORDTYPE_NS:
             case DNS_RECORDTYPE_PTR:
                 if (($_labels = $this->getLabels($info['rdlength'])) === false) {
                     return false;
                 }
                 $specific_fields = array('dname' => new DNSName($_labels));
                 break;
             case DNS_RECORDTYPE_TXT:
                 if (($_labels = $this->getLabels($info['rdlength'])) === false) {
                     return false;
                 }
                 $specific_fields = array('text' => $_labels);
                 break;
             case DNS_RECORDTYPE_MX:
                 if (($buf = $this->readStreamDirectly(2)) === false) {
                     return false;
                 }
                 $specific_fields = unpack('npreference', $buf);
                 if (($_labels = $this->getLabels($info['rdlength'] - 2)) === false) {
                     return false;
                 }
                 $specific_fields['exchange'] = new DNSName($_labels);
                 break;
             case DNS_RECORDTYPE_A:
                 if (($buf = $this->readStreamDirectly(4)) === false) {
                     return false;
                 }
                 $specific_fields = array('address' => DNSName::newFromString(implode('.', unpack('Ca/Cb/Cc/Cd', $buf))));
                 break;
             case DNS_RECORDTYPE_AAAA:
                 if (($buf = $this->readStreamDirectly(16)) === false) {
                     return false;
                 }
                 $specific_fields = array('address' => DNSName::newFromString(implode('.', unpack('Ca/Cb/Cc/Cd/Ce/Cf/Cg/Ch/Ci/Cj/Ck/Cl/Cm/Cn/Co/Cp', $buf)) . '.IP6.ARPA'));
                 break;
             case DNS_RECORDTYPE_SOA:
                 $specific_fields = array();
                 if (($_labels = $this->getLabels($info['rdlength'])) === false) {
                     return false;
                 }
                 $specific_fields['source'] = new DNSName($_labels);
                 if (($_labels = $this->getLabels($info['rdlength'])) === false) {
                     return false;
                 }
                 $specific_fields['resp_person'] = array_shift($_labels) . '@';
                 $specific_fields['resp_person'] .= implode('.', $_labels);
                 if (($buf = $this->readStreamDirectly(20)) === false) {
                     return false;
                 }
                 $specific_fields = array_merge($specific_fields, unpack('Nserial/Nrefresh/Nretry/Nexpire/Nminttl', $buf));
                 break;
             default:
                 if ($this->readStreamDirectly($info['rdlength']) === false) {
                     return false;
                 }
                 $specific_fields = false;
         }
         $recs[] = new DNSRecord(new DNSName($labels), $info['type'], $info['dclass'], $info['ttl'], $specific_fields);
     }
     return $recs;
 }