From c2f4b75978698f282b8caa93c276acdff870939b Mon Sep 17 00:00:00 2001 From: lukehamburg Date: Wed, 8 Feb 2017 10:35:52 -0500 Subject: 3rd try! - incorporate suggestions from @rbgarga with slight modification (cherry picked from commit 6c2f093000b05285546e81dd1a578fc9b573b72b) --- src/etc/inc/util.inc | 17 ++++++++--------- src/usr/local/www/services_dhcp_edit.php | 2 -- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 418ad51..a205cdb 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -1850,24 +1850,23 @@ function alias_expand_urltable($name) { /* obtain MAC address given an IP address by looking at the ARP/NDP table */ function arp_get_mac_by_ip($ip) { - unset($arp_ndp_output); + unset($macaddr); + $retval = 1; 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); + $macaddr = exec("/usr/sbin/arp -n " . escapeshellarg($ip) . " | /usr/bin/awk '{print $4}'", $output, $retval); 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); + $macaddr = exec("/usr/sbin/ndp -n " . escapeshellarg($ip) . " | /usr/bin/awk '{print $2}'", $output, $retval); break; } - if ($arp_ndp_output[0]) { - $macaddr = $arp_ndp_output[0]; - if (is_macaddr($macaddr)) { - return $macaddr; - } + if ($retval == 0 && is_macaddr($macaddr)) { + return $macaddr; + } else { + return false; } - return false; } /* return a fieldname that is safe for xml usage */ diff --git a/src/usr/local/www/services_dhcp_edit.php b/src/usr/local/www/services_dhcp_edit.php index 22bfbcf..ecdd015 100644 --- a/src/usr/local/www/services_dhcp_edit.php +++ b/src/usr/local/www/services_dhcp_edit.php @@ -404,8 +404,6 @@ if ($_POST) { // Get our MAC address $ip = $_SERVER['REMOTE_ADDR']; - -unset($mymac); $mymac = arp_get_mac_by_ip($ip); $iflist = get_configured_interface_with_descr(); -- cgit v1.1