Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/NetworkAddress.php

    r870 r873  
    1616  function GetNetMask()
    1717  {
    18     return(((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1));
     18    return (((1 << IPV4_BIT_WIDTH) - 1) ^ ((1 << (IPV4_BIT_WIDTH - $this->Prefix)) - 1));
    1919  }
    2020
    2121  function AddressToString()
    2222  {
    23     return(implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))));
     23    return (implode('.', array(($this->Address >> 24) & 255, ($this->Address >> 16) & 255, ($this->Address >> 8) & 255, ($this->Address & 255))));
    2424  }
    2525
     
    3939    $To->Address = $From->Address + $HostMask;
    4040    $To->Prefix = IPV4_BIT_WIDTH;
    41     return(array('From' => $From, 'To' => $To));
     41    return (array('From' => $From, 'To' => $To));
    4242  }
    4343
     
    4545  {
    4646    $this->Prefix = $NewPrefix;
    47     if($this->Prefix > IPV4_BIT_WIDTH) $this->Prefix = IPV4_BIT_WIDTH;
    48     if($this->Prefix < 0) $this->Prefix = 0;
     47    if ($this->Prefix > IPV4_BIT_WIDTH) $this->Prefix = IPV4_BIT_WIDTH;
     48    if ($this->Prefix < 0) $this->Prefix = 0;
    4949    $this->Address = $this->Address & $this->GetNetMask();
    5050  }
     
    5353  {
    5454    $UpperNetmask = $this->GetNetMask();
    55     if(($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true;
     55    if (($this->Prefix < $Address->Prefix) and (($Address->Address & $UpperNetmask) == ($this->Address & $UpperNetmask))) $Result = true;
    5656      else $Result = false;
    57     return($Result);
     57    return ($Result);
    5858  }
    5959}
     
    7474  function GetNetMask()
    7575  {
    76     return(Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)),
     76    return (Int128Xor(Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH)), IntToInt128(1)),
    7777      Int128Sub(Int128Shl(IntToInt128(1), IntToInt128(IPV6_BIT_WIDTH - $this->Prefix)), IntToInt128(1))));
    7878  }
     
    8080  function AddressToString()
    8181  {
    82     return(inet_ntop($this->Address));
     82    return (inet_ntop($this->Address));
    8383  }
    8484
     
    9191  {
    9292    $this->Prefix = $NewPrefix;
    93     if($this->Prefix > IPV6_BIT_WIDTH) $this->Prefix = IPV6_BIT_WIDTH;
    94     if($this->Prefix < 0) $this->Prefix = 0;
     93    if ($this->Prefix > IPV6_BIT_WIDTH) $this->Prefix = IPV6_BIT_WIDTH;
     94    if ($this->Prefix < 0) $this->Prefix = 0;
    9595    $this->Address = Int128And($this->Address, $this->GetNetMask());
    9696  }
     
    100100    $Result = array();
    101101    $Data = array_reverse(unpack('C*', $this->Address));
    102     foreach($Data as $Item)
     102    foreach ($Data as $Item)
    103103    {
    104104
     
    106106      $Result[] = dechex(($Item >> 4) & 15);
    107107    }
    108     return($Result);
     108    return ($Result);
    109109  }
    110110
     
    127127  {
    128128    $UpperNetmask = $this->GetNetMask();
    129     if(($this->Prefix < $Address->Prefix) and ((Int128Equal(Int128And($Address->Address, $UpperNetmask), Int128And($this->Address, $UpperNetmask))))) $Result = true;
     129    if (($this->Prefix < $Address->Prefix) and ((Int128Equal(Int128And($Address->Address, $UpperNetmask), Int128And($this->Address, $UpperNetmask))))) $Result = true;
    130130      else $Result = false;
    131     return($Result);
     131    return ($Result);
    132132  }
    133133}
Note: See TracChangeset for help on using the changeset viewer.