#!/bin/sh -
#
#        $OpenBSD: netstart,v 1.44 1998/10/06 23:25:21 deraadt Exp $

set `ifconfig le0`
IPADDR=$8
hostname=`grep $IPADDR /etc/hosts | awk '{print $2}'`

hostname $hostname
if [ -f /etc/defaultdomain ]; then
        domainname `cat /etc/defaultdomain`
fi

# pick up option configuration
. /etc/rc.conf

# Configure the IP filter before configuring network interfaces
#if [ X"${ipfilter}" = X"YES" -a -f "${ipfilter_rules}" ]; then
#        echo 'configuring IP filter'
#        ipf -Fa -f ${ipfilter_rules} -E
#else
        ipfilter=NO
#fi

# set the address for the loopback interface
ifconfig lo0 inet localhost

# use loopback, not the wire
route -n add -host $hostname localhost
route -n add -net 127 127.0.0.1 -reject

(
    tmp="$IFS"
    IFS="$IFS."
    set -- `echo /etc/hostname*`
    IFS=$tmp
    unset tmp

    while [ $# -ge 2 ] ; do
        shift            # get rid of "hostname"
        (
            read af name mask bcaddr extras
            read dt dtaddr
#JML
            bcaddr="255.255.255.0"

            if [ ! -n "$name" ]; then
                echo "/etc/hostname.$1: invalid network configuration file"
                exit
            fi

            cmd="ifconfig $1 $af $name "
            if [ "${dt}" = "dest" ]; then cmd="$cmd $dtaddr"; fi
            if [ -n "$mask" ]; then cmd="$cmd netmask $mask"; fi
            if [ -n "$bcaddr" -a "X$bcaddr" != "XNONE" ]; then
                cmd="$cmd broadcast $bcaddr";
            fi
            cmd="$cmd $extras";

            $cmd
        ) < /etc/hostname.$1
        shift
    done
)

# default multicast route
route -n add -net 224.0.0.0 -interface $hostname

# Configure NAT after configuring network interfaces
if [ "${ipnat}" = "YES" -a "${ipfilter}" = "YES" -a -f "${ipnat_rules}" ]; then
        echo 'configuring NAT'
        ipnat -CF -f ${ipnat_rules}
else
        ipnat=NO
fi

