Esempio n. 1
0
 function Net_DNS_RR_SRV(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $a = unpack("@{$offset}/npreference/nweight/nport", $data);
             $offset += 6;
             list($target, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
             $this->preference = $a['preference'];
             $this->weight = $a['weight'];
             $this->port = $a['port'];
             $this->target = $target;
         }
     } else {
         ereg("([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)[ \t]*\$", $data, $regs);
         $this->preference = $regs[1];
         $this->weight = $regs[2];
         $this->port = $regs[3];
         $this->target = ereg_replace('(.*)\\.$', '\\1', $regs[4]);
     }
 }
Esempio n. 2
0
 function Net_DNS_RR_SOA(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             list($mname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
             list($rname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
             $a = unpack("@{$offset}/N5soavals", $data);
             $this->mname = $mname;
             $this->rname = $rname;
             $this->serial = $a['soavals1'];
             $this->refresh = $a['soavals2'];
             $this->retry = $a['soavals3'];
             $this->expire = $a['soavals4'];
             $this->minimum = $a['soavals5'];
         }
     } else {
         if (ereg("([^ \t]+)[ \t]+([^ \t]+)[ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]+([0-9]+)[^ \t]*\$", $string, $regs)) {
             $this->mname = ereg_replace('(.*)\\.$', '\\1', $regs[1]);
             $this->rname = ereg_replace('(.*)\\.$', '\\1', $regs[2]);
             $this->serial = $regs[3];
             $this->refresh = $regs[4];
             $this->retry = $regs[5];
             $this->expire = $regs[6];
             $this->minimum = $regs[7];
         }
     }
 }
Esempio n. 3
0
 function Net_DNS_RR_MX(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $a = unpack("@{$offset}/npreference", $data);
             $offset += 2;
             $packet = new Net_DNS_Packet();
             list($exchange, $offset) = $packet->dn_expand($data, $offset);
             $this->preference = $a['preference'];
             $this->exchange = $exchange;
         }
     } elseif (is_array($data)) {
         $this->preference = $data['preference'];
         $this->exchange = $data['exchange'];
     } else {
         preg_match("/([0-9]+)[ \t]+(.+)[ \t]*\$/", $data, $regs);
         $this->preference = $regs[1];
         $this->exchange = preg_replace('/(.*)\\.$/', '\\1', $regs[2]);
     }
 }
Esempio n. 4
0
 function Net_DNS_RR_TSIG(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $packet = new Net_DNS_Packet();
             list($alg, $offset) = $packet->dn_expand($data, $offset);
             $this->algorithm = $alg;
             $d = unpack("@{$offset}/nth/Ntl/nfudge/nmac_size", $data);
             $time_high = $d['th'];
             $time_low = $d['tl'];
             $this->time_signed = $time_low;
             $this->fudge = $d['fudge'];
             $this->mac_size = $d['mac_size'];
             $offset += 10;
             $this->mac = substr($data, $offset, $this->mac_size);
             $offset += $this->mac_size;
             $d = unpack("@{$offset}/noid/nerror/nolen", $data);
             $this->original_id = $d['oid'];
             $this->error = $d['error'];
             $this->other_len = $d['olen'];
             $offset += 6;
             if ($this->other_len) {
                 $odata = substr($data, $offset, $this->other_len);
                 $d = unpack('nodata_high/Nodata_low', $odata);
                 $this->other_data = $d['odata_low'];
             }
         }
     } elseif (is_array($data)) {
         $this->key = $data['key'];
         $this->algorithm = $data['algorithm'];
         $this->time_signed = $data['time_signed'];
         $this->fudge = $data['fudge'];
         $this->mac = $data['mac'];
         $this->original_id = $data['original_id'];
         $this->error = $data['error'];
         $this->other_len = $data['other_len'];
         $this->other_data = $data['other_data'];
     } else {
         if (strlen($data) && preg_match('/^(.*)$/', $data, $regs)) {
             $this->key = $regs[1];
         }
         $this->algorithm = NET_DNS_DEFAULT_ALGORITHM;
         $this->time_signed = time();
         $this->fudge = NET_DNS_DEFAULT_FUDGE;
         $this->mac_size = 0;
         $this->mac = '';
         $this->original_id = 0;
         $this->error = 0;
         $this->other_len = 0;
         $this->other_data = '';
         // RFC 2845 Section 2.3
         $this->class = 'ANY';
     }
 }
Esempio n. 5
0
 function Net_DNS_RR_SRV(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $a = unpack("@{$offset}/npreference/nweight/nport", $data);
             $offset += 6;
             $packet = new Net_DNS_Packet();
             list($target, $offset) = $packet->dn_expand($data, $offset);
             $this->preference = $a['preference'];
             $this->weight = $a['weight'];
             $this->port = $a['port'];
             $this->target = $target;
         }
     } elseif (is_array($data)) {
         $this->preference = $data['preference'];
         $this->weight = $data['weight'];
         $this->port = $data['port'];
         $this->target = $data['target'];
     } else {
         preg_match("/([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+(.+)[ \t]*\$/", $data, $regs);
         $this->preference = $regs[1];
         $this->weight = $regs[2];
         $this->port = $regs[3];
         $this->target = preg_replace('/(.*)\\.$/', '\\1', $regs[4]);
     }
 }
Esempio n. 6
0
 function Net_DNS_RR_SOA(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $packet = new Net_DNS_Packet();
             list($mname, $offset) = $packet->dn_expand($data, $offset);
             list($rname, $offset) = $packet->dn_expand($data, $offset);
             $a = unpack("@{$offset}/N5soavals", $data);
             $this->mname = $mname;
             $this->rname = $rname;
             $this->serial = $a['soavals1'];
             $this->refresh = $a['soavals2'];
             $this->retry = $a['soavals3'];
             $this->expire = $a['soavals4'];
             $this->minimum = $a['soavals5'];
         }
     } elseif (is_array($data)) {
         $this->mname = $data['mname'];
         $this->rname = $data['rname'];
         $this->serial = $data['serial'];
         $this->refresh = $data['refresh'];
         $this->retry = $data['retry'];
         $this->expire = $data['expire'];
         $this->minimum = $data['minimum'];
     } else {
         if (preg_match("/([^ \t]+)[ \t]+([^ \t]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]*\$/", $data, $regs)) {
             $this->mname = preg_replace('/(.*)\\.$/', '\\1', $regs[1]);
             $this->rname = preg_replace('/(.*)\\.$/', '\\1', $regs[2]);
             $this->serial = $regs[3];
             $this->refresh = $regs[4];
             $this->retry = $regs[5];
             $this->expire = $regs[6];
             $this->minimum = $regs[7];
         }
     }
 }
Esempio n. 7
0
 function Net_DNS_RR_RP(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $packet = new Net_DNS_Packet();
             list($this->mboxdname, $offset) = $packet->dn_expand($data, $offset);
             list($this->txtdname, $offset) = $packet->dn_expand($data, $offset);
         }
     } elseif (is_array($data)) {
         $this->mboxdname = $data['mboxdname'];
         $this->txtdname = $data['txtdname'];
     } else {
         preg_match("/([^ ]+)\\s+([^ ]+)/", $data, $matches);
         $this->mboxdname = preg_replace('/\\.$/', '', $matches[1]);
         $this->txtdname = preg_replace('/\\.$/', '', $matches[2]);
     }
 }
Esempio n. 8
0
 function Net_DNS_RR_NAPTR(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $a = unpack("@{$offset}/norder/npreference", $data);
             $offset += 4;
             $packet = new Net_DNS_Packet();
             list($flags, $offset) = Net_DNS_Packet::label_extract($data, $offset);
             list($services, $offset) = Net_DNS_Packet::label_extract($data, $offset);
             list($regex, $offset) = Net_DNS_Packet::label_extract($data, $offset);
             list($replacement, $offset) = $packet->dn_expand($data, $offset);
             $this->order = $a['order'];
             $this->preference = $a['preference'];
             $this->flags = $flags;
             $this->services = $services;
             $this->regex = $regex;
             $this->replacement = $replacement;
         }
     } elseif (is_array($data)) {
         $this->order = $data['order'];
         $this->preference = $data['preference'];
         $this->flags = $data['flags'];
         $this->services = $data['services'];
         $this->regex = $data['regex'];
         $this->replacement = $data['replacement'];
     } else {
         $data = str_replace('\\\\', chr(1) . chr(1), $data);
         /* disguise escaped backslash */
         $data = str_replace('\\"', chr(2) . chr(2), $data);
         /* disguise \" */
         preg_match('/([0-9]+)[ \\t]+([0-9]+)[ \\t]+("[^"]*"|[^ \\t]*)[ \\t]+("[^"]*"|[^ \\t]*)[ \\t]+("[^"]*"|[^ \\t]*)[ \\t]+(.*?)[ \\t]*$/', $data, $regs);
         $this->preference = $regs[1];
         $this->weight = $regs[2];
         foreach ($regs as $idx => $value) {
             $value = str_replace(chr(2) . chr(2), '\\"', $value);
             $value = str_replace(chr(1) . chr(1), '\\\\', $value);
             $regs[$idx] = stripslashes($value);
         }
         $this->flags = $regs[3];
         $this->services = $regs[4];
         $this->regex = $regs[5];
         $this->replacement = $regs[6];
     }
 }
 function Net_DNS_RR_CNAME(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             list($cname, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
             $this->cname = $cname;
         }
     } else {
         $this->cname = ereg_replace("[ \t]+(.+)[\\. \t]*\$", '\\1', $data);
     }
 }
Esempio n. 10
0
 function Net_DNS_RR_CNAME(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $packet = new Net_DNS_Packet();
             list($cname, $offset) = $packet->dn_expand($data, $offset);
             $this->cname = $cname;
         }
     } elseif (is_array($data)) {
         $this->cname = $data['cname'];
     } else {
         $this->cname = preg_replace("/[ \t]+(.+)[\\. \t]*\$/", '\\1', $data);
     }
 }
Esempio n. 11
0
 function Net_DNS_RR_MX(&$rro, $data, $offset = '')
 {
     $this->name = $rro->name;
     $this->type = $rro->type;
     $this->class = $rro->class;
     $this->ttl = $rro->ttl;
     $this->rdlength = $rro->rdlength;
     $this->rdata = $rro->rdata;
     if ($offset) {
         if ($this->rdlength > 0) {
             $a = unpack("@{$offset}/npreference", $data);
             $offset += 2;
             list($exchange, $offset) = Net_DNS_Packet::dn_expand($data, $offset);
             $this->preference = $a['preference'];
             $this->exchange = $exchange;
         }
     } else {
         ereg("([0-9]+)[ \t]+(.+)[ \t]*\$", $data, $regs);
         $this->preference = $regs[1];
         $this->exchange = ereg_replace('(.*)\\.$', '\\1', $regs[2]);
     }
 }
Esempio n. 12
0
 /**
  * DNS packet decompression method
  *
  * Expands the domain name stored at a particular location in a DNS
  * packet.  The first argument is a variable containing  the packet
  * data.  The second argument is the offset within the  packet where
  * the (possibly) compressed domain name is stored.
  *
  * @param   string  $packet The packet data
  * @param   integer $offset The location offset in the packet of the
  *                          label to decompress.
  * @return  array   Returns a list of type array($name, $offset) where
  *                  $name is the name of the label which was decompressed
  *                  and $offset is the offset of the next field in the
  *                  packet.  Returns array(null, null) on error
  */
 function dn_expand($packet, $offset)
 {
     $packetlen = strlen($packet);
     $name = '';
     while (1) {
         if ($packetlen < $offset + 1) {
             return array(null, null);
         }
         $a = unpack("@{$offset}/Cchar", $packet);
         $len = (int) $a['char'];
         if ($len == 0) {
             $offset++;
             break;
         } else {
             if (($len & 0xc0) == 0xc0) {
                 if ($packetlen < $offset + Net_DNS_Packet::INT16SZ) {
                     return array(null, null);
                 }
                 $ptr = unpack("@{$offset}/ni", $packet);
                 $ptr = $ptr['i'];
                 $ptr = $ptr & 0x3fff;
                 $name2 = Net_DNS_Packet::dn_expand($packet, $ptr);
                 if (is_null($name2[0])) {
                     return array(null, null);
                 }
                 $name .= $name2[0];
                 $offset += Net_DNS_Packet::INT16SZ;
                 break;
             } else {
                 $offset++;
                 if ($packetlen < $offset + $len) {
                     return array(null, null);
                 }
                 $elem = substr($packet, $offset, $len);
                 $name .= $elem . '.';
                 $offset += $len;
             }
         }
     }
     $name = preg_replace('/\\.$/', '', $name);
     return array($name, $offset);
 }