diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2006-04-15 15:28:19 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2006-04-15 15:28:19 +0000 |
commit | 4eb3e9fb47c4a7386357f84f288b11a292614300 (patch) | |
tree | ae248b9ef89129689d6f1e3404ea16578be049cd | |
parent | 65437f222ef40c58f8f55078a490081e70a20833 (diff) | |
download | pfsense-4eb3e9fb47c4a7386357f84f288b11a292614300.zip pfsense-4eb3e9fb47c4a7386357f84f288b11a292614300.tar.gz |
MFC 11429
use route to figure out what interface an IP is on
-rw-r--r-- | etc/inc/pfsense-utils.inc | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index dd86a9b..ef05848 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -511,24 +511,9 @@ function find_interface_ip($interface) { } function guess_interface_from_ip($ipaddress) { - $ints = `/sbin/ifconfig -l`; - $ints_split = split(" ", $ints); - $ip_subnet_split = split("\.", $ipaddress); - $ip_subnet = $ip_subnet_split[0] . "." . $ip_subnet_split[1] . "." . $ip_subnet_split[2] . "."; - /* check first 3 octets */ - foreach($ints_split as $int) { - $ip = find_interface_ip($int); - $ip_split = split("\.", $ip); - $ip_tocheck = $ip_split[0] . "." . $ip_split[1] . "." . $ip_split[2] . "."; - if(stristr($ip_subnet, $ip_tocheck) != false) return $int; - } - /* check first 2 octets since nothing found while checking 3 */ - foreach($ints_split as $int) { - $ip = find_interface_ip($int); - $ip_split = split("\.", $ip); - $ip_tocheck = $ip_split[0] . "." . $ip_split[1] . "."; - if(stristr($ip_subnet, $ip_tocheck) != false) return $int; - } + $ret = exec_command("/sbin/route get {$ipaddress} | /usr/bin/grep interface | /usr/bin/awk '{ print \$2 +; };'"); + return $ret; } function filter_opt_interface_to_real($opt) { @@ -2152,4 +2137,4 @@ function update_filter_reload_status($text) { config_unlock(); } -?>
\ No newline at end of file +?> |