#!/bin/sh
#
# dhcpd         This shell script takes care of starting and stopping
#               dhcpd.
#
# chkconfig: 345 65 35
# description: dhcpd provide access to Dynamic Host Control Protocol.

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/sbin/dhcpd ] || exit 0
[ -f /etc/dhcpd.conf ] || exit 0

RETVAL=0

start(){
# Start daemons.
	[ -f "/etc/conf.linuxconf" ] && DEV=`perl -ne "if (/DHCP.interface /) {print $'};" /etc/conf.linuxconf`
    	if [ "$DEV" == "" ]
		then
        	echo "no dhcp in /etc/conf.linuxconf, get eth0 as default interface "
        	DEV="eth0"
    	fi
    echo -n "Starte DHCP-Dmon (dhcpd): "
    daemon /usr/sbin/dhcpd $DEV
        echo -n "Adding local broadcast host route: "
	/sbin/route add -net 255.255.255.255 netmask 255.255.255.255 dev $DEV
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
    return $RETVAL
}

stop(){
	# Stop daemons.
    echo -n "Stoppe DHCP-Dmon (dhcpd): "
    killproc dhcpd
        RETVAL=$?
    echo -n "Killing host route we defined at startup: "
    /sbin/route del 255.255.255.255
	echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dhcpd
    return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start	
	;;
  stop)
	stop
	;;
  restart)
	stop
    	start
    	RETVAL=$?
	;;
  reload)
        stop
        start
        RETVAL=$?  
	;;
  status)
	status dhcpd
        RETVAL=$?
;;
  *)
	echo "Usage: dhcpd {start|stop|restart|status}"
	RETVAL=1
esac

exit $RETVAL
