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

Source for file ipcalc.php

Documentation is available at ipcalc.php

  1. <?php
  2. /**
  3.  * Project: IPCALC :: IP calculator / subnetting<br>
  4.  * File:    IPCALC.php
  5.  *
  6.  * 이 class는 IP 계산과 서브네팅을 지원한다.
  7.  *
  8.  * @category    Networking
  9.  * @package     IPCALC
  10.  * @author      JoungKyun.Kim <http://oops.org>
  11.  * @copyright   (c) 2018, JoungKyun.Kim
  12.  * @license     LGPL
  13.  * @link        http://pear.oops.org/package/ipcalc
  14.  * @since       File available since release 0.0.1
  15.  * @example     IPCALC/test.php Sample code of IPCLAC class
  16.  * @filesource
  17.  */
  18.  
  19. /**
  20.  * import IPCALCLogic class
  21.  */
  22. require_once 'IPCALC/IPCALC.php';
  23.  
  24. /**
  25.  * IPCALC 의 frontend Class
  26.  * @package    IPCALC
  27.  */
  28. class IPCALC extends IPCALCLogic
  29. {
  30.     // {{{ (void) IPCALC::__construct (void)
  31.     /**
  32.      * Initialize IPCALC class
  33.      *
  34.      * @access    public
  35.      * @return    void 
  36.      */
  37.     function __construct (}
  38.     // }}}
  39.  
  40.     // {{{ (long) IPCALC::ip2long ($ip)
  41.     /**
  42.      * Dot로 구분된 IPv4 주소를 정수형 주소로 변환
  43.      *
  44.      * PHP의 ip2long API가 singed 형이기 때문에 음수의 값이 나올 수
  45.      * 있어, 이 API를 제공하여 항상 양수의 값이 나올 수 있도록 지원.
  46.      *
  47.      * {@example IPCALC/test.php 18 3}
  48.      *
  49.      * @access    public
  50.      * @return    long   unsigned 형의 정수형 네트워크 주소
  51.      * @param    string Dot로 구분된 IPv4 주소
  52.      */
  53.     static function ip2long ($ip{
  54.         return parent::ip2long ($ip);
  55.     }
  56.     // }}}
  57.  
  58.     /**
  59.      * alias IPCALC::valid_ipv4_addr
  60.      */
  61.     static function is_ipaddr ($ip{
  62.         return parent::valid_ipv4_addr ($ip);
  63.     }
  64.  
  65.     // {{{ (boolean) IPCALC::valid_ipv4_addr ($ip)
  66.     /**
  67.      * 인자로 주어진 값이 정상적인 IPv4 주소인지를 체크
  68.      *
  69.      * {@example IPCALC/test.php 24 2}
  70.      *
  71.      * @access    public
  72.      * @return    boolean 정상적인 IP일 경우 true, 그 외 false
  73.      * @param    string  Dot로 구분된 IPv4 주소
  74.      */
  75.     static function valid_ipv4_addr ($ip{
  76.         return parent::valid_ipv4_addr ($ip);
  77.     }
  78.     // }}}
  79.  
  80.     // {{{ (string) IPCALC::prefix2mask ($prefix)
  81.     /**
  82.      * 네트워크 prefix를 네트워크 mask로 변환
  83.      *
  84.      * {@example IPCALC/test.php 29 2}
  85.      *
  86.      * @access  public
  87.      * @return  string  네트워크 mask
  88.      * @param   integer    네트워크 prefix
  89.      */
  90.     static function prefix2mask ($prefix{
  91.         $r parent::prefix2long ($prefix);
  92.         return long2ip ($r);
  93.     }
  94.     // }}}
  95.  
  96.     // {{{ (int) IPCALC::mask2prefix ($mask)
  97.     /**
  98.      * 네트워크 mask를 네트워크 prefix로 변환
  99.      *
  100.      * {@example IPCALC/test.php 33 2}
  101.      *
  102.      * @access  public
  103.      * @return  int    네트워크 prefix
  104.      * @param   string 네트워크 mask
  105.      */
  106.     static function mask2prefix ($mask{
  107.         $mask ip2long ($mask);
  108.         return parent::long2prefix ($mask);
  109.     }
  110.     // }}}
  111.  
  112.     // {{{ (string) IPCALC::network ($ip, $mask) {
  113.     /**
  114.      * 주어진 IPv4 주소와 네트워크 mask로 구성된 서브넷의 네트워크
  115.      * 주소를 반환
  116.      *
  117.      * {@example IPCALC/test.php 37 2}
  118.      *
  119.      * @access  public
  120.      * @return  string 해당 서브넷의 네트워크 주소
  121.      * @param   string IPv4 주소
  122.      * @param   string 네트워크 mask 또는 prefix
  123.      */
  124.     static function network ($ip$mask{
  125.         $r parent::network ($ip$mask);
  126.         return long2ip ($r);
  127.     }
  128.     // }}}
  129.  
  130.     // {{{ (string) IPCALC::broadcast ($ip, $mask)
  131.     /**
  132.      * 주어진 IPv4 주소와 네트워크 mask로 구성된 서브넷의 브로드캐스트
  133.      * 주소를 반환
  134.      *
  135.      * {@example IPCALC/test.php 41 2}
  136.      *
  137.      * @access    public
  138.      * @return    string  해당 서브넷의 브로드캐스트 주소
  139.      * @param    string    IPv4 주소 또는 long형 주소값
  140.      * @param    string    네트워크 mask
  141.      */
  142.     static function broadcast ($ip$mask{
  143.         $r parent::broadcast ($ip$mask);
  144.         return long2ip ($r);
  145.     }
  146.     // }}}
  147.  
  148.     // {{{ (int) IPCALC::guess_prefix ($start, $end)
  149.     /**
  150.      * 시작 주소와 마지막 주소를 포함한 서브넷의 prefix를 반환
  151.      *
  152.      * {@example IPCALC/test.php 45 2}
  153.      *
  154.      * @access  public
  155.      * @return  int            네트워크 prefix
  156.      * @param   string      범위의 시작 IPv4 주소
  157.      * @param   string      범위의 마지막 IPv4 주소
  158.      */
  159.     static function guess_prefix ($start$end{
  160.         return parent::guess_prefix ($start$end);
  161.     }
  162.     // }}}
  163.  
  164.     // {{{ (string) IPCALC::guess_netmask ($start, $end)
  165.     /**
  166.      * 시작 주소와 마지막 주소를 포함한 서브넷의 최소 mask를 반환
  167.      *
  168.      * {@example IPCALC/test.php 49 2}
  169.      *
  170.      * @access  public
  171.      * @return  string        네트워크 mask
  172.      * @param   string      범위의 시작 IPv4 주소
  173.      * @param   string      범위의 마지막 IPv4 주소
  174.      */
  175.     static function guess_netmask ($start$end{
  176.         return parent::guess_netmask ($start$end);
  177.     }
  178.     // }}}
  179.  
  180.     // {{{ (binary) IPCALC::htonl ($v)
  181.     /**
  182.      * 4 Byte unsigned 정수를 host byte order에서 network byte
  183.      * order로 변환
  184.      *
  185.      * x86/x86_64 cpu에서는 little endian을 big endian으로 변환
  186.      * 하는 것과 동일 함
  187.      *
  188.      * @access    public
  189.      * @return    binary        network byte order로 변환된 binary
  190.      * @param    int            4 Byte 양수형 정수
  191.      */
  192.     static function htonl ($v{
  193.         return pack ('N'$v);
  194.     }
  195.     // }}}
  196.  
  197.     // {{{ (long) IPCALC::ntohl ($v)
  198.     /**
  199.      * Network oerder byte로 구성된 4 Byte 정수 binary data를
  200.      * signed 정수로 변환
  201.      *
  202.      * x86/x86_64 cpu에서는 big endian을 little endian으로 변환
  203.      * 하는 것과 동일 함
  204.      *
  205.      * @access    public
  206.      * @return    long        4 Byte signed 정수
  207.      * @param    binary        Network byte order로 구성된 4Byte 정수 binary
  208.      */
  209.     static function ntohl ($v{
  210.         for $i=3$i>=0$i-- )
  211.             $v1 .= $v[$i];
  212.  
  213.         $val unpack ('ilittle'$v1);
  214.         return $val['little'];
  215.     }
  216.     // }}}
  217. }
  218.  
  219. /*
  220.  * Local variables:
  221.  * tab-width: 4
  222.  * c-basic-offset: 4
  223.  * End:
  224.  * vim600: noet sw=4 ts=4 fdm=marker
  225.  * vim<600: noet sw=4 ts=4
  226.  */
  227. ?>

Documentation generated on Tue, 14 May 2019 02:00:07 +0900 by phpDocumentor 1.4.4