Revision 2a819956
Added by Colin Smith almost 20 years ago
etc/inc/util.inc | ||
---|---|---|
97 | 97 |
|
98 | 98 |
/* returns true if $ipaddr is a valid dotted IPv4 address or an alias thereof */ |
99 | 99 |
function is_ipaddroralias($ipaddr) { |
100 |
|
|
101 | 100 |
global $aliastable, $config; |
102 | 101 |
|
103 | 102 |
if(is_array($config['aliases']['alias'])) { |
... | ... | |
231 | 230 |
/* returns a list of interfaces with MAC addresses |
232 | 231 |
(skips VLAN and other virtual interfaces) */ |
233 | 232 |
function get_interface_list() { |
234 |
/* build interface list with netstat */ |
|
235 |
exec("/usr/bin/netstat -inW -f link", $linkinfo); |
|
236 |
array_shift($linkinfo); |
|
237 |
|
|
238 |
$iflist = array(); |
|
239 |
|
|
240 |
foreach ($linkinfo as $link) { |
|
241 |
$alink = preg_split("/\s+/", $link); |
|
242 |
$ifname = chop($alink[0]); |
|
243 |
|
|
244 |
if (substr($ifname, -1) == "*") |
|
245 |
$ifname = substr($ifname, 0, strlen($ifname) - 1); |
|
246 |
|
|
247 |
if (!preg_match("/^(plip|pflog|pfsync|ppp|sl|gif|faith|lo|ng|vlan)/", $ifname)) { |
|
248 |
$iflist[$ifname] = array(); |
|
249 |
|
|
250 |
$iflist[$ifname]['mac'] = chop($alink[3]); |
|
251 |
$iflist[$ifname]['up'] = false; |
|
252 |
|
|
253 |
/* find out if the link on this interface is up */ |
|
254 |
unset($ifinfo); |
|
255 |
exec("/sbin/ifconfig {$ifname}", $ifinfo); |
|
256 |
|
|
257 |
foreach ($ifinfo as $ifil) { |
|
258 |
if (preg_match("/status: (.*)$/", $ifil, $matches)) { |
|
259 |
if ($matches[1] == "active") |
|
260 |
$iflist[$ifname]['up'] = true; |
|
261 |
break; |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
return $iflist; |
|
233 |
/* get a list of virtual interface types */ |
|
234 |
$vfaces = explode(" ", trim(shell_exec("/sbin/ifconfig -C"))); |
|
235 |
$upints = explode(" ", trim(shell_exec("/sbin/ifconfig -lu"))); |
|
236 |
/* build interface list with netstat */ |
|
237 |
exec("/usr/bin/netstat -inW -f link | awk '{ print $1, $4 } '", $linkinfo); |
|
238 |
array_shift($linkinfo); |
|
239 |
foreach ($linkinfo as $link) { |
|
240 |
$alink = explode(" ", $link); |
|
241 |
$ifname = rtrim(trim($alink[0]), '*'); |
|
242 |
if (!in_array(substr($ifname, 0, -1), $vfaces)) { |
|
243 |
$iflist[$ifname]['mac'] = trim($alink[1]); |
|
244 |
$iflist[$ifname]['up'] = in_array($ifname, $upints) ? true: false; |
|
245 |
/* find out if the link on this interface is up */ |
|
246 |
} |
|
247 |
} |
|
248 |
return $iflist; |
|
268 | 249 |
} |
269 | 250 |
|
270 | 251 |
/* wrapper for exec() */ |
Also available in: Unified diff
Rewrite get_interface_list(). It now grabs a list of interface cloners instead of using a static list, makes fewer shell calls (more noticeable on systems with many interfaces), and does not use the preg engine.