#
# sample.dip	Dialup IP connection support program.
#		This file shows in a very verbose way how to use dip
#		and its commands to establish a link to a host.
#
#		To show, how I developed this script, see the file
#		samples/ReadMe.HowTo.  I will show you the output
#		delivered by my host and some other details.
#
#		Hope, it will help you to use dip in a simple way...
#		
#
# Version:	@(#)samples/sample.dip	1.02	1.July.1995
#
#
# Author:	Joachim Bartz, <injb@sun.rz.tu-clausthal.de>
#
#
#		This program is free software; you can redistribute it
#		and/or  modify it under  the terms of  the GNU General
#		Public  License as  published  by  the  Free  Software
#		Foundation;  either  version 2 of the License, or  (at
#		your option) any later version.
#
#		This program is  distributed in the  hope that it will
#		be useful, but WITHOUT ANY WARRANTY;  without even the
#		implied warranty of MERCHANTABILITY  or  FITNESS FOR A
#		PARTICULAR  PURPOSE.    See  the  GNU  General  Public
#		License for more details.
#
#		You  should have received  a copy  of the  GNU General
#		Public License along with this program;  if not, write
#		to the
#			Free Software Foundation, Inc.
#			675 Mass Ave
#			Cambridge, MA 02139, USA
#

set_modem:
	port tty01
	speed 57600
	get $counter 0

reset_modem:
	reset
	wait 5 OK ERROR
	if $errlvl ==  2  goto error_reset_modem
	if $errlvl == -1  goto timeout

	print Modem at port $port is reset.

	init ATE0L2M1X7&K4
	print Modem init string set.

dial_out:
	inc $counter
	print Now dialing... Try No.: $counter
	dial TELEPHONE-NUMBER
	wait 5 OK ERROR
	if $errlvl ==  2  goto error_init_string

dial_wait:
	wait 60 CONNECT BUSY CARRIER DIALTONE ANSWER RINGING
	if $errlvl ==  6  goto dial_wait
	if $errlvl ==  5  goto dial_noanswer
	if $errlvl ==  4  goto dial_nodialtone
	if $errlvl ==  3  goto dial_nocarrier
	if $errlvl ==  2  goto dial_out
	if $errlvl == -1  goto timeout

login:
	wait 10 Host:
	if $errlvl != 1  goto login_error

	send slip\n

	wait 10 Login:
	if $errlvl != 1  goto login_error

	send MYACCOUNT\n

	wait 10 Password:
	if $errlvl != 1  goto login_error

	send MYPASSWORD\n

	wait 10 My\sIP\sis:
	if $errlvl != 1  goto getip_error
	get $rmtip remote 10

	wait 10 Your\sIP\sis:
	if $errlvl != 1  goto getip_error
	get $locip remote 10

#	wait 10 Netmask\sis:
#	if $errlvl != 1  goto getip_error
#	get $netmask remote

#	get $mtu 296

	default

	print Local IP ... $locip
	print Remote IP .. $rmtip
	print Netmask .... $netmask
	print MTU ........ $mtu
	print
	print Connected!
	print
	wait 10 starting
	mode CSLIP

        if $errlvl == -1  goto mode_pidfileerror
        if $errlvl !=  1  goto exit2
        print
        print The DIP daemon lost the carrier and the connection.
        print Trying to build up a new one...
        get $counter 0
        goto dial_out

mode_pidfileerror:
        print Fatal error: "mode" returned -1 (creating pid file)
        goto exit

getip_error:
	print Got CONNECT and login, but no IPs! Sorry...
	print Lokale IP .. $locip
	print Remote IP .. $rmtip
	print Netmask .... $netmask
	print MTU ........ $mtu
	reset
	goto exit

login_error:
	print Got CONNECT, but no chance to log in!
	reset
	goto exit

dial_nocarrier:
	print Got NO CARRIER !
	goto exit

dial_nodialtone:
	print Got NO DIALTONE !
	goto exit

dial_noanswer:
	print Got NO ANSWER !
	goto exit

error_init_string:
	print Error initializing the modem.
	print Aborting dial out!
	reset
	goto exit

error_reset_modem:
	print Error resetting the modem at port $port .
	goto exit

timeout:
	print Timeout or other error occurred. Sorry...
	goto exit

exit:
	print Exiting.

exit2:

