feature: Add q-bridge-mib tagged VLAN membership #3285

This commit is contained in:
Eldon Koyle
2016-10-11 15:29:06 -06:00
committed by Neil Lathwood
parent 626ce47b0f
commit 7ca80410d5
8 changed files with 152 additions and 27 deletions

View File

@@ -1647,3 +1647,41 @@ function getCIMCentPhysical($location, &$entphysical, &$index)
return $index;
} // end if - Level 1
} // end function
/* idea from http://php.net/manual/en/function.hex2bin.php comments */
function hex2bin_compat($str)
{
if (strlen($str) % 2 !== 0) {
trigger_error(__FUNCTION__.'(): Hexadecimal input string must have an even length', E_USER_WARNING);
}
return pack("H*", $str);
}
if (!function_exists('hex2bin')) {
// This is only a hack
function hex2bin($str)
{
return hex2bin_compat($str);
}
}
function q_bridge_bits2indices($hex_data)
{
/* convert hex string to an array of 1-based indices of the nonzero bits
* ie. '9a00' -> '100110100000' -> array(1, 4, 5, 7)
*/
$hex_data = str_replace(' ', '', $hex_data);
$value = hex2bin($hex_data);
$length = strlen($value);
$indices = array();
for ($i = 0; $i < $length; $i++) {
$byte = ord($value[$i]);
for ($j = 7; $j >= 0; $j--) {
if ($byte & (1 << $j)) {
$indices[] = 8*$i + 8-$j;
}
}
}
return $indices;
}