Revision 9ff8c299
Added by Seth Mos over 15 years ago
etc/inc/interfaces.inc | ||
---|---|---|
2396 | 2396 |
return $wanif; |
2397 | 2397 |
} |
2398 | 2398 |
|
2399 |
/* Guess the physical interface by providing a IP address */ |
|
2399 | 2400 |
function guess_interface_from_ip($ipaddress) { |
2400 |
$ret = `/usr/bin/netstat -rn | /usr/bin/awk '/^{$ipaddress}/ {printf "%s", \$6}'`; |
|
2401 |
if (empty($ret)) |
|
2402 |
return false; |
|
2403 |
|
|
2404 |
return $ret; |
|
2401 |
if(! is_ipaddress($ipaddress)) { |
|
2402 |
return false; |
|
2403 |
} |
|
2404 |
/* create a route table we can search */ |
|
2405 |
exec("netstat -rn", $output, $ret); |
|
2406 |
foreach($output as $line) { |
|
2407 |
if(preg_match("/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+[ ]+link[#]/", $line)) { |
|
2408 |
$fields = preg_split("/[ ]+/", $line); |
|
2409 |
if(ip_in_subnet($ipaddress, $fields[0])) { |
|
2410 |
return $fields[5]; |
|
2411 |
} |
|
2412 |
} |
|
2413 |
} |
|
2414 |
$ret = exec_command("/sbin/route -n get {$ipaddress} | /usr/bin/awk '/interface/ { print \$2; };'"); |
|
2415 |
if(empty($ret)) { |
|
2416 |
return false; |
|
2417 |
} |
|
2418 |
return $ret; |
|
2405 | 2419 |
} |
2406 | 2420 |
|
2407 | 2421 |
/* |
Also available in: Unified diff
Forward port the guess_interface_from_ip() from 1.2-RELEASE TO 2.0
This one works far better then the old one that was still in 2.0.
Problem being, if it was not in the ARP cache it was not in the route table.