diff options
author | lukehamburg <luke.hamburg@gmail.com> | 2017-02-08 03:13:08 -0500 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2017-02-10 15:57:52 -0200 |
commit | 307243e7b7cb88283740ae29a2d6150cc59bc573 (patch) | |
tree | 857b98cc5c1aa9674f10939b9b8c13c50f4db164 /src/etc | |
parent | 9a20d17098ee74a96370aeeb0fd9a1fcf7f8d86c (diff) | |
download | pfsense-307243e7b7cb88283740ae29a2d6150cc59bc573.zip pfsense-307243e7b7cb88283740ae29a2d6150cc59bc573.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()
(cherry picked from commit dd83f869b79a858bd74c7a8bb4adcd49217445b0)
Diffstat (limited to 'src/etc')
-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 8d8a083..418ad51 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -1848,22 +1848,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; } |