Net_DNS
[ class tree: Net_DNS ] [ index: Net_DNS ] [ all elements ]

Source for file AAAA.php

Documentation is available at AAAA.php

  1. <?php
  2. /*
  3.  *  License Information:
  4.  *
  5.  *    Net_DNS:  A resolver library for PHP
  6.  *    Copyright (c) 2002-2003 Eric Kilfoil eric@ypass.net
  7.  *
  8.  *    This library is free software; you can redistribute it and/or
  9.  *    modify it under the terms of the GNU Lesser General Public
  10.  *    License as published by the Free Software Foundation; either
  11.  *    version 2.1 of the License, or (at your option) any later version.
  12.  *
  13.  *    This library is distributed in the hope that it will be useful,
  14.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  *    Lesser General Public License for more details.
  17.  *
  18.  *    You should have received a copy of the GNU Lesser General Public
  19.  *    License along with this library; if not, write to the Free Software
  20.  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.  */
  22.  
  23.  
  24. /* Net_DNS_RR_AAAA object definition {{{ */
  25. /**
  26.  * A representation of a resource record of type <b>AAAA</b>
  27.  *
  28.  * @package Net_DNS
  29.  */
  30. class Net_DNS_RR_AAAA extends Net_DNS_RR
  31. {
  32.     /* class variable definitions {{{ */
  33.     var $name;
  34.     var $type;
  35.     var $class;
  36.     var $ttl;
  37.     var $rdlength;
  38.     var $rdata;
  39.     var $address;
  40.  
  41.     /* }}} */
  42.     /* class constructor - Net_DNS_RR_AAAA(&$rro, $data, $offset = '') {{{ */
  43.     function Net_DNS_RR_AAAA(&$rro$data$offset '')
  44.     {
  45.         $this->name = $rro->name;
  46.         $this->type = $rro->type;
  47.         $this->class = $rro->class;
  48.         $this->ttl = $rro->ttl;
  49.         $this->rdlength = $rro->rdlength;
  50.         $this->rdata = $rro->rdata;
  51.  
  52.         if ($offset{
  53.             $this->address = Net_DNS_RR_AAAA::ipv6_decompress(substr($this->rdata0$this->rdlength));
  54.         else {
  55.             if (strlen($data)) {
  56.                 if (count($adata explode(':'$data8)) >= 3{
  57.                     foreach($adata as $addr)
  58.                         if (!preg_match('/^[0-9A-F]{0,4}$/i'$addr)) return;
  59.                     $this->address = trim($data);
  60.                 }
  61.             }
  62.         
  63.     }
  64.  
  65.     /* }}} */
  66.     /* Net_DNS_RR_AAAA::rdatastr() {{{ */
  67.     function rdatastr()
  68.     {
  69.         if (strlen($this->address)) {
  70.             return $this->address;
  71.         }
  72.         return '; no data';
  73.     }
  74.     /* }}} */
  75.     /* Net_DNS_RR_AAAA::rr_rdata($packet, $offset) {{{ */
  76.     function rr_rdata($packet$offset)
  77.     {
  78.         return Net_DNS_RR_AAAA::ipv6_compress($this->address);
  79.     }
  80.  
  81.     /* }}} */
  82.     /* Net_DNS_RR_AAAA::ipv6_compress($addr) {{{ */
  83.     function ipv6_compress($addr)
  84.     {
  85.         $numparts count(explode(':'$addr));
  86.         if ($numparts < 3 || $numparts > 8 ||
  87.             !preg_match('/^([0-9A-F]{0,4}:){0,7}(:[0-9A-F]{0,4}){0,7}$/i'$addr)) {
  88.             /* Non-sensical IPv6 address */
  89.             return pack('n8'00000000);
  90.         }
  91.         if (strpos($addr'::'!== false{
  92.             /* First we have to normalize the address, turn :: into :0:0:0:0: */
  93.             $filler str_repeat(':0'9 - $numparts':';
  94.             if (substr($addr02== '::'{
  95.                 $filler = "0$filler";
  96.             }
  97.             if (substr($addr-22== '::'{
  98.                 $filler .= '0';
  99.             }
  100.             $addr str_replace('::'$filler$addr);
  101.         }
  102.         $aparts explode(':'$addr);
  103.         return pack('n8'hexdec($aparts[0])hexdec($aparts[1])hexdec($aparts[2])hexdec($aparts[3]),
  104.                           hexdec($aparts[4])hexdec($aparts[5])hexdec($aparts[6])hexdec($aparts[7]));
  105.     }
  106.     /* }}} */
  107.  
  108.     /* Net_DNS_RR_AAAA::ipv6_decompress($pack) {{{ */
  109.     function ipv6_decompress($pack)
  110.     {
  111.         if (strlen($pack!= 16{
  112.             /* Must be 8 shorts long */
  113.             return '::';
  114.         }
  115.         $a unpack('n8'$pack);
  116.         $addr vsprintf("%x:%x:%x:%x:%x:%x:%x:%x"$a);
  117.         /* Shorthand the first :0:0: set into a :: */
  118.         /* TODO: Make this is a single replacement pattern */
  119.         if (substr($addr-4== ':0:0'{
  120.             return preg_replace('/((:0){2,})$/''::'$addr);
  121.         elseif (substr($addr04== '0:0:'{
  122.             return '0:0:'substr($addr4);
  123.         else {
  124.             return preg_replace('/(:(0:){2,})/''::'$addr);
  125.         }
  126.     }
  127.  
  128.     /* }}} */
  129. }
  130. /* }}} */
  131. /* VIM settings {{{
  132.  * Local variables:
  133.  * tab-width: 4
  134.  * c-basic-offset: 4
  135.  * soft-stop-width: 4
  136.  * c indent on
  137.  * End:
  138.  * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  139.  * vim<600: sw=4 ts=4
  140.  * }}} */
  141. ?>

Documentation generated on Mon, 11 Mar 2019 14:35:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.