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,62 +871,57 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "") ...@@ -870,62 +871,57 @@ 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]), '*'); $toput = array(
/* trim out all numbers before checking for vfaces */ 'up' => in_array($ifname, $upints),
if (!in_array(array_shift(preg_split('/\d/', $ifname)), $vfaces) && 'ipaddr' => $ifdata['ipaddr'],
!stristr($ifname, "_vlan") && !stristr($ifname, "_wlan")) { 'mac' => $ifdata['macaddr']
$toput = array( );
"mac" => trim($alink[1]),
"up" => in_array($ifname, $upints) $friendly = '';
); if (isset($config['interfaces'])) {
foreach($ipinfo as $ip) { foreach($config['interfaces'] as $name => $int) {
$aip = explode(" ", $ip); if ($int['if'] == $ifname) {
if($aip[0] == $ifname) { $friendly = $name;
$toput['ipaddr'] = $aip[1];
}
}
if (isset($config['interfaces'])) {
foreach($config['interfaces'] as $name => $int) {
if($int['if'] == $ifname) $friendly = $name;
} }
} }
switch($keyby) { }
case "physical":
if($friendly != "") {
$toput['friendly'] = $friendly;
}
$dmesg_arr = array();
exec("/sbin/dmesg |grep $ifname | head -n1", $dmesg_arr);
preg_match_all("/<(.*?)>/i", $dmesg_arr[0], $dmesg);
if (isset($dmesg[1][0])) {
$toput['dmesg'] = $dmesg[1][0];
} else {
$toput['dmesg'] = null;
}
$iflist[$ifname] = $toput;
break;
case "ppp":
case "friendly": switch ($keyby) {
if($friendly != "") { case 'physical':
$toput['if'] = $ifname; if ($friendly != '') {
$iflist[$friendly] = $toput; $toput['friendly'] = $friendly;
}
break;
} }
$dmesg_arr = array();
exec("/sbin/dmesg |grep $ifname | head -n1", $dmesg_arr);
preg_match_all("/<(.*?)>/i", $dmesg_arr[0], $dmesg);
if (isset($dmesg[1][0])) {
$toput['dmesg'] = $dmesg[1][0];
} else {
$toput['dmesg'] = null;
}
$iflist[$ifname] = $toput;
break;
case 'friendly':
case 'ppp':
if ($friendly != '') {
$toput['if'] = $ifname;
$iflist[$friendly] = $toput;
}
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