/[baselayout]/trunk/net.BSD/ifconfig.sh
Gentoo

Contents of /trunk/net.BSD/ifconfig.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2690 - (show annotations) (download) (as text)
Tue May 8 16:52:26 2007 UTC (11 years, 5 months ago) by uberlord
File MIME type: text/x-sh
File size: 2453 byte(s)
When we don't have an address return 1, #176577.
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 ifconfig_depend() {
5 program /sbin/ifconfig
6 provide interface
7 }
8
9 _exists() {
10 [ -e /dev/net/"${IFACE}" ]
11 }
12
13 _get_mac_address() {
14 local mac=$(LC_ALL=C ifconfig "${IFACE}" | \
15 sed -n -e 's/^[[:space:]]*ether \(..:..:..:..:..:..\).*/\1/p')
16
17 case "${mac}" in
18 00:00:00:00:00:00) ;;
19 44:44:44:44:44:44) ;;
20 FF:FF:FF:FF:FF:FF) ;;
21 *) echo "${mac}"; return 0 ;;
22 esac
23
24 return 1
25 }
26
27 _up () {
28 ifconfig "${IFACE}" up
29 }
30
31 _down () {
32 ifconfig "${IFACE}" down
33 }
34
35 _ifindex() {
36 local x=
37 for x in /dev/net[0-9]* ; do
38 if [ "${x}" -ef /dev/net/"${IFACE}" ] ; then
39 echo "${x#/dev/net}"
40 return 0
41 fi
42 done
43 return 1
44 }
45
46 _is_wireless() {
47 LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | \
48 grep -q "^[[:space:]]*media: IEEE 802.11 Wireless"
49 }
50
51 _get_inet_address() {
52 set -- $(LC_ALL=C ifconfig "${IFACE}" |
53 sed -n -e 's/^[[:space:]]*inet \([^ ]*\) netmask 0x\(..\)\(..\)\(..\)\(..\).*/\1 0x\2.0x\3.0x\4/p')
54 [ -z "$1" ] && return 1
55
56 echo -n "$1"
57 shift
58 echo "/$(_netmask2cidr "$1")"
59 }
60
61 _add_address() {
62 if [ "${metric:-0}" != "0" ] ; then
63 set -- "$@" metric ${metric}
64 fi
65
66 ifconfig "${IFACE}" add "$@"
67 }
68
69 _add_route() {
70 if [ $# -gt 3 ] ; then
71 if [ "$3" = "gw" -o "$3" = "via" ] ; then
72 local one=$1 two=$2
73 shift ; shift; shift
74 set -- "${one}" "${two}" "$@"
75 fi
76 fi
77
78 route add "$@"
79 }
80
81 _delete_addresses() {
82 # We don't remove addresses from aliases
83 case "${IFACE}" in
84 *:*) return 0 ;;
85 esac
86
87 einfo "Removing addresses"
88 eindent
89 local addr=
90 for addr in $(LC_ALL=C ifconfig "${IFACE}" |
91 sed -n -e 's/^[[:space:]]*inet \([^ ]*\).*/\1/p') ; do
92 if [ "${addr}" = "127.0.0.1" ] ; then
93 # Don't delete the loopback address
94 [ "$1" = "lo" -o "$1" = "lo0" ] && continue
95 fi
96 einfo "${addr}"
97 /sbin/ifconfig "$1" delete "${addr}"
98 eend $?
99 done
100
101 # Remove IPv6 addresses
102 for addr in $(LC_ALL=C ifconfig "${IFACE}" | \
103 sed -n -e 's/^[[:space:]]*inet6 \([^ ]*\).*/\1/p') ; do
104 case "${addr}" in
105 *"%${IFACE}") continue ;;
106 ::1) continue ;;
107 esac
108 einfo "${addr}"
109 /sbin/ifconfig "${IFACE}" inet6 delete "${addr}"
110 eend $?
111 done
112
113 return 0
114 }
115
116 _show_address() {
117 einfo "received address $(_get_inet_address "${IFACE}")"
118 }
119
120 _has_carrier() {
121 local s=$(LC_ALL=C ifconfig "${IFACE}" | \
122 sed -n -e 's/^[[:space:]]status: \(.*\)$/\1/p')
123 [ -z "${s}" -o "${s}" = "active" -o "${s}" = "associated" ]
124 }
125
126 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20