home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / A.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  3.2 KB  |  110 lines

  1. <?php
  2. /*
  3.  *  License Information:
  4.  *
  5.  *    Net_DNS:  A resolver library for PHP
  6.  *    Copyright (C) 2002 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_A object definition {{{ */
  25. /**
  26.  * A representation of a resource record of type <b>A</b>
  27.  *
  28.  * @package Net_DNS
  29.  */
  30. class Net_DNS_RR_A 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.     /* class constructor - Net_DNS_RR_A(&$rro, $data, $offset = "") {{{ */
  42.     function Net_DNS_RR_A(&$rro, $data, $offset = "")
  43.     {
  44.         $this->name = $rro->name;
  45.         $this->type = $rro->type;
  46.         $this->class = $rro->class;
  47.         $this->ttl = $rro->ttl;
  48.         $this->rdlength = $rro->rdlength;
  49.         $this->rdata = $rro->rdata;
  50.  
  51.         if ($offset) {
  52.             if ($this->rdlength > 0) {
  53.                 /*
  54.                  *  We don't have inet_ntoa in PHP?
  55.                  */
  56.                 $aparts = unpack("C4b", $this->rdata);
  57.                 $addr = $aparts["b1"] . "." .
  58.                     $aparts["b2"] . "." .
  59.                     $aparts["b3"] . "." .
  60.                     $aparts["b4"];
  61.                 $this->address = $addr;
  62.             }
  63.         } else {
  64.             if (strlen($data) && ereg("([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)[ \t]*$", $data, $regs)) {
  65.                 if (($regs[1] >= 0 && $regs[1] <= 255) &&
  66.                         ($regs[2] >= 0 && $regs[2] <= 255) &&
  67.                         ($regs[3] >= 0 && $regs[3] <= 255) &&
  68.                         ($regs[4] >= 0 && $regs[4] <= 255)) {
  69.                     $this->address = $regs[1] . "." . $regs[2] . "." . $regs[3] . "." .$regs[4];
  70.                 }
  71.             }
  72.         } 
  73.     }
  74.  
  75.     /* }}} */
  76.     /* Net_DNS_RR_A::rdatastr() {{{ */
  77.     function rdatastr()
  78.     {
  79.         if (strlen($this->address)) {
  80.             return($this->address);
  81.         }
  82.         return("; no data");
  83.     }
  84.     /* }}} */
  85.     /* Net_DNS_RR_A::rr_rdata($packet, $offset) {{{ */
  86.     function rr_rdata($packet, $offset)
  87.     {
  88.         $aparts = split("\.", $this->address);
  89.         if (count($aparts) == 4) {
  90.             return(pack("c4", $aparts[0], $aparts[1], $aparts[2], $aparts[3]));
  91.         }
  92.         return(NULL);
  93.     }
  94.  
  95.     /* }}} */
  96.  
  97. }
  98. /* }}} */
  99. /* VIM settings {{{
  100.  * Local variables:
  101.  * tab-width: 4
  102.  * c-basic-offset: 4
  103.  * soft-stop-width: 4
  104.  * c indent on
  105.  * End:
  106.  * vim600: sw=4 ts=4 sts=4 cindent fdm=marker et
  107.  * vim<600: sw=4 ts=4
  108.  * }}} */
  109. ?>
  110.