diff options
author | lukehamburg <luke.hamburg@gmail.com> | 2017-02-08 03:13:08 -0500 |
---|---|---|
committer | lukehamburg <luke.hamburg@gmail.com> | 2017-02-08 03:13:08 -0500 |
commit | dd83f869b79a858bd74c7a8bb4adcd49217445b0 (patch) | |
tree | 03d2b442e3d3e105e238ae3c0f8150df32dcca08 /src/etc/inc/util.inc | |
parent | 478e89190a295b48d221ddf2f683cac6f02d7012 (diff) | |
download | pfsense-dd83f869b79a858bd74c7a8bb4adcd49217445b0.zip pfsense-dd83f869b79a858bd74c7a8bb4adcd49217445b0.tar.gz |
2nd try. . .
/etc/inc/util.inc:
- arp_get_mac_by_ip() updated to support IPv6
- attempt at code streamline
/usr/local/www/services_dhcp_edit.php:
- streamline code, now just a simple call to arp_get_mac_by_ip()
Diffstat (limited to 'src/etc/inc/util.inc')
-rw-r--r-- | src/etc/inc/util.inc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index fb116c1..f5a2fb6 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -1811,22 +1811,25 @@ function alias_expand_urltable($name) { return null; } -/* obtain MAC address given an IP address by looking at the ARP table */ +/* obtain MAC address given an IP address by looking at the ARP/NDP table */ function arp_get_mac_by_ip($ip) { - mwexec("/sbin/ping -c 1 -t 1 " . escapeshellarg($ip), true); - $arpoutput = ""; - exec("/usr/sbin/arp -n " . escapeshellarg($ip), $arpoutput); - - if ($arpoutput[0]) { - $arpi = explode(" ", $arpoutput[0]); - $macaddr = $arpi[3]; + unset($arp_ndp_output); + switch (is_ipaddr($ip)) { + case 4: + mwexec("/sbin/ping -c 1 -t 1 " . escapeshellarg($ip), true); + exec("/usr/sbin/arp -n " . escapeshellarg($ip) . " | /usr/bin/awk '{print $4}'", $arp_ndp_output); + break; + case 6: + mwexec("/sbin/ping6 -c 1 -X 1 " . escapeshellarg($ip), true); + exec("/usr/sbin/ndp -n " . escapeshellarg($ip) . " | /usr/bin/tail -n+2 | /usr/bin/awk '{print $2}'", $arp_ndp_output); + break; + } + if ($arp_ndp_output[0]) { + $macaddr = $arp_ndp_output[0]; if (is_macaddr($macaddr)) { return $macaddr; - } else { - return false; } } - return false; } |