diff options
author | Ermal Luçi <eri@pfsense.org> | 2009-03-22 23:19:40 +0000 |
---|---|---|
committer | Ermal Luçi <eri@pfsense.org> | 2009-03-22 23:19:40 +0000 |
commit | f2ba47f8daf76bcbdf62f77ab7e89776eb6314cf (patch) | |
tree | d1fa8b1145a845d5dba091b00eaab61327dfebf0 /etc | |
parent | 82ef398ab3b2250ae80f01cf267eebe2ba64aaf0 (diff) | |
download | pfsense-f2ba47f8daf76bcbdf62f77ab7e89776eb6314cf.zip pfsense-f2ba47f8daf76bcbdf62f77ab7e89776eb6314cf.tar.gz |
* Keep only one function to return the mac address
* Bring the mac address function to interfaces.inc its the only consumer of those.
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/interfaces.inc | 30 | ||||
-rw-r--r-- | etc/inc/pfsense-utils.inc | 32 |
2 files changed, 22 insertions, 40 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index f5826a5..fadb3eb 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -1274,7 +1274,7 @@ function interface_configure($interface = "wan") { mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " link " . escapeshellarg($wancfg['spoofmac'])); } else { - $mac = get_interface_mac_address($wancfg['if']); + $mac = get_interface_mac($wancfg['if']); if($mac == "ff:ff:ff:ff:ff:ff") { /* this is not a valid mac address. generate a * temporary mac address so the machine can get online. @@ -1968,13 +1968,27 @@ function get_wireless_modes($interface) { } function get_interface_mac($interface) { - /* build interface list with netstat */ - $linkinfo = ""; - exec("/usr/bin/netstat -I $interface -nW -f link", $linkinfo); - array_shift($linkinfo); - $alink = preg_split("/\s+/", $linkinfo[0]); - $mac = chop($alink[3]); - return $mac; + $mac = exec("ifconfig {$interface} | awk '/ether/ {print $2}'"); + if(is_macaddr($mac)) { + return trim($mac); + } else { + return ""; + } +} + +/****f* pfsense-utils/generate_random_mac_address + * NAME + * generate_random_mac - generates a random mac address + * INPUTS + * none + * RESULT + * $mac - a random mac address + ******/ +function generate_random_mac_address() { + $mac = "02"; + for($x=0; $x<5; $x++) + $mac .= ":" . dechex(rand(16, 255)); + return $mac; } function setup_pppoe_reset_file($interface, $status) { diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 188df75..9d6403d 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -826,23 +826,6 @@ function log_error($error) { return; } -/****f* pfsense-utils/get_interface_mac_address - * NAME - * get_interface_mac_address - Return a interfaces mac address - * INPUTS - * $interface - interface to obtain mac address from - * RESULT - * $mac - the mac address of the interface - ******/ -function get_interface_mac_address($interface) { - $mac = exec("ifconfig {$interface} | awk '/ether/ {print $2}'"); - if(is_macaddr($mac)) { - return trim($mac); - } else { - return ""; - } -} - /****f* pfsense-utils/return_dir_as_array * NAME * return_dir_as_array - Return a directory's contents as an array. @@ -2468,21 +2451,6 @@ function display_topbar($text = "", $bg_color="#990000", $replace_color="#FFFFFF echo "</script>"; } -/****f* pfsense-utils/generate_random_mac_address - * NAME - * generate_random_mac - generates a random mac address - * INPUTS - * none - * RESULT - * $mac - a random mac address - ******/ -function generate_random_mac_address() { - $mac = "02"; - for($x=0; $x<5; $x++) - $mac .= ":" . dechex(rand(16, 255)); - return $mac; -} - /****f* pfsense-utils/strncpy * NAME * strncpy - copy strings |