#!/usr/local/sbin/slipsh
#
# Sample slips script. Customize by setting the variables below
# to apropriate values. Mode can be one of SLIP, CSLIP, ADAPTIVE,
# and SLIP6.
#
# This script takes up the SLIP link, and waits until either the link
# comes down, or it is signalled to do so. In addition, it monitors
# traffic on the link and takes down the link after n seconds of
# inactivity.
#
set device	ttyS1
set telnos	555-1234
# or: 
#set telnos	{555-1234 555-6789}
set login	joedoe
set passwd	melrose
set retries	6
set mode	CSLIP
set local	myhost.fnord.org
set remote	otherhost.foobar.com
set inactive	360

source /usr/local/lib/slipsh/common.tcl

#
# lock and open device
#
tty lock $device
set ttyfd [tty open -user root -group tty -mode 0664 $device]

#
# dial the remote system and log in
#
set dial [dialup $device $ttyfd $telnos $login $passwd $retries]
if {$dial != ""} {
    tty close $ttyfd
    tty unlock $device
    exit 2
}

#
# convert line to SLIP
#
set iface [setslip $mode $ttyfd $local $remote]
route add $remote dev $iface
route add default gw $remote

#
# become daemon and wait forever
#
set pid [daemon $device $ttyfd]
if {$pid != 0} {
	# We're the parent process. Write the system lock and exit.
	log_pid $pid $remote $iface
	exit 0
}

#
# loop and check the interface stats every $inactive seconds
#
net ifstats -ipackets ipkt -opackets opkt $iface
while 1 {
	sys sleep $inactive
	net ifstats -ipackets ipkt2 -opackets opkt2 $iface
	if {$ipkt == $ipkt2 && $opkt == $opkt2} {
		# Harold, what does that mean: harikari?
		sys kill SIGHUP 0
	}
	set ipkt $ipkt2
	set opkt $opkt2
}
