Commit c1aaa80d authored by Franco Fichtner's avatar Franco Fichtner

interfaces: portable alternative for php module function

(cherry picked from commit 2533e110)
(cherry picked from commit b17d74fa)
parent f06eee33
...@@ -259,3 +259,40 @@ function configure_interface_hardware($ifs) ...@@ -259,3 +259,40 @@ function configure_interface_hardware($ifs)
} }
} }
} }
function legacy_getall_interface_addresses($ifs)
{
$cmd = '/sbin/ifconfig ' . escapeshellarg($ifs);
$addrs = array();
exec($cmd . ' 2>&1', $out, $ret);
if ($ret) {
log_error('The command `' . $cmd . '\' failed to execute');
return $addrs;
}
if (count($out)) {
foreach ($out as $line) {
if ($line[0] != "\t") {
continue;
}
$stat = explode(' ', $line);
if (isset($stat[0])) {
switch (trim($stat[0])) {
case 'inet':
$mask = substr_count(base_convert(hexdec($stat[3]), 10, 2), '1');
$addrs[] = $stat[1] . '/' . $mask;
break;
case 'inet6':
$addrs[] = strtok($stat[1], '%') . '/' . $stat[3];
break;
default:
/* not relevant to our interest */
break;
}
}
}
}
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