You are here

function _field_ipaddress_long2cidr in IP address fields 7

Convert a start address and end address (as longs) into a CIDR.

The start address is assumed to be the start of a well-defined block.

2 calls to _field_ipaddress_long2cidr()
field_ipaddress_field_formatter_view in ./field_ipaddress.module
Implements hook_field_formatter_view().
field_ipaddress_field_widget_form in ./field_ipaddress.module
Implements hook_field_widget_form().

File

./field_ipaddress.module, line 313

Code

function _field_ipaddress_long2cidr($start, $end) {
  $mask = (int) $start | ~(int) $end;
  $cidr = 32 - log(abs($mask), 2);
  $valid = (int) $cidr == $cidr;
  if (!$valid) {
    return _field_ipaddress_long2shorthand($start, $end);
  }
  return long2ip($start) . '/' . $cidr;
}