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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 534 - (hide annotations) (download)
Thu Aug 12 04:29:53 2004 UTC (13 years, 11 months ago) by agriffis
Original Path: trunk/net-scripts/net.modules.d/macchanger
File size: 2439 byte(s)
- Get rid of "interface" and "interface_provides" functions, instead
  dynamically generate class functions instead when modules are
  loaded.
- Double-check when loading modules to make sure that functions aren't
  replaced
- Sanity check user-specified module list to make sure none conflict
- Get ride of IFMODULE

1 agriffis 532 # macchanger module for net-scripts
2     # Copyright 2004 Gentoo Foundation
3     # Distributed under the terms of the GNU General Public License v2
4     # Contributed by Roy "UberLord" Marples <uberlord@rsm.demon.co.uk>
5     # $Header$
6     #
7     # Based on code from Gentoo Linux /etc/init.d/net.eth0 version 1.45
8    
9     # char* macchanger_provides(void)
10     #
11     # Returns a string to change module definition for starting up
12     macchanger_provides() {
13     echo "macchanger"
14     }
15    
16     # bool macchanger_check_installed(void)
17     #
18     # Returns 1 if macchanger is installed, otherwise 0
19     macchanger_check_installed() {
20     [[ -x /sbin/macchanger ]] && return 0
21     [[ true == ${1} ]] && eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
22     return 1
23     }
24    
25     # int macchanger_priority(void)
26     #
27     # Returns the priority of the module - lower is more important
28     macchanger_priority() {
29     echo 0
30     }
31    
32     # bool macchanger_check_depends(void)
33     #
34     # Checks to see if we have the necessary package installed
35     # and the handler supports the necessary functionality
36     macchanger_check_depends() {
37     local e
38    
39 agriffis 534 [[ function != $(typeset -f interface_get_address) ]] && e=interface_get_address
40 agriffis 532 [[ -z ${e} ]] && return 0
41    
42     eerror "macchanger: interface is missing the required function ${e}\n"
43     return 1
44     }
45    
46     # bool macchanger_pre_start(char *iface)
47     #
48     # Configures the MAC address for iface
49     macchanger_pre_start() {
50     local iface=${1} mac opts e
51    
52     eval mac=\"\$\{mac_${iface}\}\"
53     [[ -z ${mac} ]] && return 0
54    
55     case "${mac}" in
56     # 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    
59     # increment MAC address, default macchanger behavior
60     increment) opts="${opts}" ;;
61    
62     # randomize just the ending bytes
63     random-ending) opts="${opts} -e" ;;
64    
65     # keep the same kind of physical layer (eg fibre, copper)
66     random-samekind) opts="${opts} -a" ;;
67    
68     # randomize to any known vendor of any physical layer type
69     random-anykind) opts="${opts} -A" ;;
70    
71     # fully random bytes
72     random-full) opts="${opts} -r" ;;
73    
74     # default case is just to pass on all the options
75     *) opts="${opts} ${mac}" ;;
76     esac
77    
78     e=$( /sbin/macchanger ${opts} ${IFACE} )
79     if [[ -n ${e} ]]; then
80     eerror "Failed to set MAC address"
81     return 1
82     fi
83    
84 agriffis 534 mac=$( interface_get_mac_address ${iface} )
85 agriffis 532 einfo " MAC address for ${iface} changed to ${mac}"
86    
87     return 0 #important
88     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20