diff options
author | luigi <luigi@FreeBSD.org> | 2001-11-29 03:16:23 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2001-11-29 03:16:23 +0000 |
commit | 068bd1c13533834bfca0cbbce16398bcaad1321f (patch) | |
tree | 00e41c8a9e2770d3f002159056e41781d360d2e3 /release/picobsd | |
parent | 0c2addad83d4e772edd16bb6aaea7b585bca9506 (diff) | |
download | FreeBSD-src-068bd1c13533834bfca0cbbce16398bcaad1321f.zip FreeBSD-src-068bd1c13533834bfca0cbbce16398bcaad1321f.tar.gz |
Implement a more efficient way to assign addresses: read /etc/hosts
only once into an array of shell variables, and then scan the array
to find entries matching the MAC address.
Associative arrays would really be handy here...
Diffstat (limited to 'release/picobsd')
-rw-r--r-- | release/picobsd/floppy.tree/etc/rc.conf | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/release/picobsd/floppy.tree/etc/rc.conf b/release/picobsd/floppy.tree/etc/rc.conf index 2926b09..40e88d1 100644 --- a/release/picobsd/floppy.tree/etc/rc.conf +++ b/release/picobsd/floppy.tree/etc/rc.conf @@ -48,43 +48,61 @@ get_ether() { ether="" set `ifconfig ${key}` while [ "$1" != "" ] ; do - if [ "$1" = "ether" ] ; then - ether=$2 - break - else - shift - fi + if [ "$1" = "ether" ] ; then + ether=$2 + break + else + shift + fi done } +# read content from /etc/hosts into an array (needed later in fetch_hostname) +read_hosts() { + local i a b c key junk + i="" + while read a b c junk ; do + if [ "$a" = "#ethertable" ] ; then + i=0 + elif [ "$i" != "" -a "X$a" = "X#" -a "$b" != "" ] ; then + eval eth_${i}=$b + eval eth_host_${i}=$c + i=$(($i+1)) + fi + done < /etc/hosts +} + # set "hostname" using $1 (ethernet address) as search key in /etc/hosts fetch_hostname() { - local a b c key junk - key=$1 # search key - hostname="" - while read a b c junk ; do - if [ "$a" = "#ethertable" ] ; then - hostname="." - elif [ "X$hostname" = "X." -a "X$a" = "X#" ] ; then - case X${key} in - X${b} ) # so we can use wildcards - hostname=$c - break - ;; - esac + local i b key + key=$1 + i=0 + b="x" + if [ "${eth_0}" = "" ] ; then + read_hosts fi - done < /etc/hosts + hostname="" + while [ "$b" != "" -a "${hostname}" = "" ] ; do + eval b=\${eth_${i}} + case X${key} in + X${b} ) # so we can use wildcards + eval hostname=\${eth_host_${i}} + break + ;; + esac + i=$(($i+1)) + done echo "fetch_hostname for <${key}> returns <${hostname}>" } # sets "mask" using $1 (netmask name) as the search key in /etc/networks fetch_mask() { - local a b c key - key=$1 # search key, typically hostname-netmask + local a b key junk + key=$1 # search key, typically hostname-netmask mask="" - while read a b c; do # key mask otherstuff + while read a b junk; do # key mask otherstuff case X${key} in - X${a} ) # we can use wildcards + X${a} ) # we can use wildcards mask=$b break ;; |