Remove our reliance on sed and grep

This commit is contained in:
Roy Marples 2007-12-04 14:19:47 +00:00
parent ba3248e6d2
commit 09f949de5e

View File

@ -39,17 +39,20 @@ _exists() {
} }
_get_mac_address() { _get_mac_address() {
local mac=$(LC_ALL=C ifconfig "${IFACE}" | \ local proto= address= foo=
sed -n -e 's/^[[:space:]]*ether \(..:..:..:..:..:..\).*/\1/p') LC_ALL=C ifconfig "${IFACE}" | while read proto address foo; do
case "${proto}" in
case "${mac}" in ether)
00:00:00:00:00:00);; case "${address}" in
44:44:44:44:44:44);; 00:00:00:00:00:00);;
FF:FF:FF:FF:FF:FF);; 44:44:44:44:44:44);;
*) echo "${mac}"; return 0;; FF:FF:FF:FF:FF:FF);;
esac *) echo "${address}";;
esac
return 1 return 0
;;
esac
done
} }
_up () { _up () {
@ -73,7 +76,7 @@ _ifindex() {
done done
;; ;;
default) default)
for x in $(ifconfig -a | sed -n -e 's/^\([^[:space:]]*\):.*/\1/p'); do for x in $(ifconfig -l); do
if [ "${x}" = "${IFACE}" ]; then if [ "${x}" = "${IFACE}" ]; then
echo "${i}" echo "${i}"
return 0 return 0
@ -88,19 +91,29 @@ _ifindex() {
return 1 return 1
} }
_ifconfig_ent() {
LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | while read ent rest; do
case "${ent}" in
"$1") echo "${rest}";;
esac
done
}
_is_wireless() { _is_wireless() {
LC_ALL=C ifconfig "${IFACE}" 2>/dev/null | \ case "$(_ifconfig_ent "media:")" in
grep -q "^[[:space:]]*media: IEEE 802.11 Wireless" "IEEE 802.11 Wireless"*) return 0;;
*) return 1;;
esac
} }
_get_inet_address() { _get_inet_address() {
set -- $(LC_ALL=C ifconfig "${IFACE}" | local inet= address= n= netmask= rest=
sed -n -e 's/^[[:space:]]*inet \([^ ]*\) netmask 0x\(..\)\(..\)\(..\)\(..\).*/\1 0x\2.0x\3.0x\4/p') LC_ALL=C ifconfig "${IFACE}" | while read inet address n netmask rest; do
[ -z "$1" ] && return 1 if [ "${inet}" = "inet" ]; then
echo "${address}/$(_netmask2cidr "${netmask}")"
echo -n "$1" return 0
shift fi
echo "/$(_netmask2cidr "$1")" done
} }
_add_address() { _add_address() {
@ -145,38 +158,22 @@ _add_route() {
} }
_delete_addresses() { _delete_addresses() {
# We don't remove addresses from aliases
case "${IFACE}" in
*:*) return 0;;
esac
einfo "Removing addresses" einfo "Removing addresses"
eindent eindent
local addr= LC_ALL=C ifconfig "${IFACE}" | while read inet address rest; do
for addr in $(LC_ALL=C ifconfig "${IFACE}" | case "${inet}" in
sed -n -e 's/^[[:space:]]*inet \([^ ]*\).*/\1/p'); do inet|inet6)
if [ "${addr}" = "127.0.0.1" ]; then case "${address}" in
# Don't delete the loopback address *"%${IFACE}"|::1) continue;;
[ "$1" = "lo" -o "$1" = "lo0" ] && continue 127.0.0.1) [ "${IFACE}" = "lo0" ] && continue;;
fi esac
einfo "${addr}" einfo "${address}"
ifconfig "$1" "${addr}" -alias ifconfig "${IFACE}" "${inet}" "${address}" -alias
eend $? eend $?
done ;;
# Remove IPv6 addresses
for addr in $(LC_ALL=C ifconfig "${IFACE}" | \
sed -n -e 's/^[[:space:]]*inet6 \([^ ]*\).*/\1/p'); do
case "${addr}" in
*"%${IFACE}") continue;;
::1) continue;;
esac esac
einfo "${addr}"
ifconfig "${IFACE}" inet6 "${addr}" -alias
eend $?
done done
eoutdent eoutdent
return 0 return 0
} }
@ -185,9 +182,10 @@ _show_address() {
} }
_has_carrier() { _has_carrier() {
local s=$(LC_ALL=C ifconfig "${IFACE}" | \ case "$(_ifconfig_ent "status:")" in
sed -n -e 's/^[[:space:]]status: \(.*\)$/\1/p') ""|active|associated) return 0;;
[ -z "${s}" -o "${s}" = "active" -o "${s}" = "associated" ] *) return 1;;
esac
} }
ifconfig_pre_start() { ifconfig_pre_start() {
@ -223,7 +221,17 @@ ifconfig_pre_start() {
} }
_ifconfig_ipv6_tentative() { _ifconfig_ipv6_tentative() {
LC_ALL=C ifconfig "${IFACE}" | grep -q "^[[:space:]]*inet6 .* tentative" local inet= address= rest=
LC_ALL=C ifconfig "${IFACE}" | while read inet address rest; do
case "${inet}" in
inet6)
case "${rest}" in
*" "tentative*) return 2;;
esac
;;
esac
done
[ $? = 2 ]
} }
ifconfig_post_start() { ifconfig_post_start() {