/[baselayout]/branches/rc-scripts-1_6/net-scripts/net.modules.d/macchanger
Gentoo

Diff of /branches/rc-scripts-1_6/net-scripts/net.modules.d/macchanger

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 662 Revision 713
22# bool macchanger_check_installed(void) 22# bool macchanger_check_installed(void)
23# 23#
24# Returns 1 if macchanger is installed, otherwise 0 24# Returns 1 if macchanger is installed, otherwise 0
25macchanger_check_installed() { 25macchanger_check_installed() {
26 [[ -x /sbin/macchanger ]] && return 0 26 [[ -x /sbin/macchanger ]] && return 0
27 [[ ${1} == true ]] && eerror "For changing MAC addresses, emerge net-analyzer/macchanger" 27 ${1:-false} && eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
28 return 1 28 return 1
29} 29}
30 30
31# bool macchanger_check_depends(void) 31# bool macchanger_check_depends(void)
32# 32#
33# Checks to see if we have the needed functions 33# Checks to see if we have the needed functions
34macchanger_check_depends() { 34macchanger_check_depends() {
35 local f 35 local f
36 36
37 for f in interface_get_mac_address; do 37 for f in interface_get_mac_address; do
38 [[ $(type -t ${f}) == function ]] && continue 38 [[ $( type -t ${f} ) == function ]] && continue
39 eerror "macchanger: missing required function ${f}\n" 39 eerror "macchanger: missing required function ${f}\n"
40 return 1 40 return 1
41 done 41 done
42 42
43 return 0 43 return 0
45 45
46# bool macchanger_pre_start(char *iface) 46# bool macchanger_pre_start(char *iface)
47# 47#
48# Configures the MAC address for iface 48# Configures the MAC address for iface
49macchanger_pre_start() { 49macchanger_pre_start() {
50 local iface=${1} mac opts e 50 local iface=${1} mac opts e old_mac new_mac
51 51
52 eval mac=\"\$\{mac_${iface}\}\" 52 eval mac=\"\$\{mac_${iface}\}\"
53 [[ -z ${mac} ]] && return 0 53 [[ -z ${mac} ]] && return 0
54 54
55 mac=$( echo ${mac} | tr '[:lower:]' '[:upper:]' )
55 case "${mac}" in 56 case "${mac}" in
56 # specific mac-addr, i wish there were a shorter way to specify this 57 # specific mac-addr, i wish there were a shorter way to specify this
57 [0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]) opts="${opts} --mac=${mac}" ;; 58 [0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]) opts="${opts} --mac=${mac}" ;;
58 59
59 # increment MAC address, default macchanger behavior 60 # increment MAC address, default macchanger behavior
60 increment) opts="${opts}" ;; 61 increment) opts="${opts}" ;;
61 62
62 # randomize just the ending bytes 63 # randomize just the ending bytes
73 74
74 # default case is just to pass on all the options 75 # default case is just to pass on all the options
75 *) opts="${opts} ${mac}" ;; 76 *) opts="${opts} ${mac}" ;;
76 esac 77 esac
77 78
78 e=$( /sbin/macchanger ${opts} ${iface} 2>&1 1>/dev/null || echo failed ) 79 # The interface needs to be up for macchanger to work
80 interface_up ${iface}
81
82 ebegin "Changing MAC address of ${iface}"
83 mac=$( /sbin/macchanger ${opts} ${iface} | awk '/Faked MAC:/ { print $3 }' )
79 if [[ -n ${e} ]]; then 84 if [[ -z ${mac} ]]; then
80 eerror "Failed to set MAC address" 85 eend 1 "Failed to set MAC address"
81 return 1 86 return 1
82 fi 87 fi
83 88
84 mac=$( interface_get_mac_address ${iface} ) 89 eend 0
85 einfo "MAC address for ${iface} changed to ${mac}" 90 eindent
91 einfo "changed to ${mac}"
92 eoutdent
86 93
87 return 0 #important 94 return 0 #important
88} 95}

Legend:
Removed from v.662  
changed lines
  Added in v.713

  ViewVC Help
Powered by ViewVC 1.1.20