Commit cfbcc72a authored by Franco Fichtner's avatar Franco Fichtner

interfaces: manually backport b676a002

parent d44f11fe
...@@ -260,10 +260,13 @@ function configure_interface_hardware($ifs) ...@@ -260,10 +260,13 @@ function configure_interface_hardware($ifs)
} }
} }
function legacy_getall_interface_addresses($ifs) function _legacy_getall_interface_addresses($ifs)
{ {
$cmd = '/sbin/ifconfig ' . escapeshellarg($ifs); $cmd = '/sbin/ifconfig ' . escapeshellarg($ifs);
$addrs = array(); $addrs = array(
'macaddr' => '00:00:00:00:00:00',
'compat' => array(),
);
exec($cmd . ' 2>&1', $out, $ret); exec($cmd . ' 2>&1', $out, $ret);
if ($ret) { if ($ret) {
...@@ -281,10 +284,27 @@ function legacy_getall_interface_addresses($ifs) ...@@ -281,10 +284,27 @@ function legacy_getall_interface_addresses($ifs)
switch (trim($stat[0])) { switch (trim($stat[0])) {
case 'inet': case 'inet':
$mask = substr_count(base_convert(hexdec($stat[3]), 10, 2), '1'); $mask = substr_count(base_convert(hexdec($stat[3]), 10, 2), '1');
$addrs[] = $stat[1] . '/' . $mask; $addrs['compat'][] = $stat[1] . '/' . $mask;
if (!isset($addrs['ipaddr'])) {
$addrs['ipaddr'] = $stat[1];
$addrs['subnetbits'] = $mask;
}
break; break;
case 'inet6': case 'inet6':
$addrs[] = strtok($stat[1], '%') . '/' . $stat[3]; $addr = strtok($stat[1], '%');
if (!isset($addrs['ipaddr6']) && strpos($addr, 'fe80:') !== 0) {
/* does not pick up link-local */
$addrs['ipaddr6'] = $addr;
for ($i = 0; $i < count($stat); ++$i) {
if ($stat[$i] == 'prefixlen') {
$addrs['subnetbits6'] = intval($stat[$i+1]);
}
}
}
$addrs['compat'][] = $addr . '/' . $addrs['subnetbits6'];
break;
case 'ether':
$addrs['macaddr'] = $stat[1];
break; break;
default: default:
/* not relevant to our interest */ /* not relevant to our interest */
...@@ -296,3 +316,16 @@ function legacy_getall_interface_addresses($ifs) ...@@ -296,3 +316,16 @@ function legacy_getall_interface_addresses($ifs)
return $addrs; return $addrs;
} }
function legacy_getall_interface_addresses($ifs)
{
$addrs = _legacy_getall_interface_addresses($ifs);
return $addrs['compat'];
}
function legacy_get_interface_addresses($ifs)
{
$addrs = _legacy_getall_interface_addresses($ifs);
unset($addrs['compat']);
return $addrs;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment