Commit b5daea15 authored by Franco Fichtner's avatar Franco Fichtner

interfaces: netstat -iW truncates output; refactor this stuff for good

parent 99a46c13
...@@ -849,7 +849,8 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "") ...@@ -849,7 +849,8 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
'ipfw' 'ipfw'
); );
} }
switch($mode) {
switch ($mode) {
case 'active': case 'active':
$upints = legacy_interface_listget('up'); $upints = legacy_interface_listget('up');
break; break;
...@@ -870,39 +871,35 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "") ...@@ -870,39 +871,35 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
$upints = legacy_interface_listget(); $upints = legacy_interface_listget();
break; break;
} }
/* build interface list with netstat */
$linkinfo = ""; $ifnames = legacy_interface_listget();
exec("/usr/bin/netstat -inW -f link | awk '{ print $1, $4 }'", $linkinfo);
array_shift($linkinfo); foreach ($ifnames as $ifname) {
/* build ip address list with netstat */ if (in_array(array_shift(preg_split('/\d/', $ifname)), $vfaces) ||
$ipinfo = ""; stristr($ifname, '_vlan') || stristr($ifname, '_wlan')) {
exec("/usr/bin/netstat -inW -f inet | awk '{ print $1, $4 }'", $ipinfo); continue;
array_shift($ipinfo); }
foreach($linkinfo as $link) {
$friendly = ""; $ifdata = pfSense_get_interface_addresses($ifname);
$alink = explode(" ", $link);
$ifname = rtrim(trim($alink[0]), '*');
/* trim out all numbers before checking for vfaces */
if (!in_array(array_shift(preg_split('/\d/', $ifname)), $vfaces) &&
!stristr($ifname, "_vlan") && !stristr($ifname, "_wlan")) {
$toput = array( $toput = array(
"mac" => trim($alink[1]), 'up' => in_array($ifname, $upints),
"up" => in_array($ifname, $upints) 'ipaddr' => $ifdata['ipaddr'],
'mac' => $ifdata['macaddr']
); );
foreach($ipinfo as $ip) {
$aip = explode(" ", $ip); $friendly = '';
if($aip[0] == $ifname) {
$toput['ipaddr'] = $aip[1];
}
}
if (isset($config['interfaces'])) { if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $name => $int) { foreach($config['interfaces'] as $name => $int) {
if($int['if'] == $ifname) $friendly = $name; if ($int['if'] == $ifname) {
$friendly = $name;
} }
} }
switch($keyby) { }
case "physical":
if($friendly != "") { switch ($keyby) {
case 'physical':
if ($friendly != '') {
$toput['friendly'] = $friendly; $toput['friendly'] = $friendly;
} }
$dmesg_arr = array(); $dmesg_arr = array();
...@@ -915,17 +912,16 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "") ...@@ -915,17 +912,16 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
} }
$iflist[$ifname] = $toput; $iflist[$ifname] = $toput;
break; break;
case "ppp": case 'friendly':
case 'ppp':
case "friendly": if ($friendly != '') {
if($friendly != "") {
$toput['if'] = $ifname; $toput['if'] = $ifname;
$iflist[$friendly] = $toput; $iflist[$friendly] = $toput;
} }
break; break;
} }
} }
}
return $iflist; return $iflist;
} }
......
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