home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
icwatch.zip
/
ICWATCH.DOC
< prev
next >
Wrap
Text File
|
1995-08-23
|
6KB
|
145 lines
ICWatch.c - Slip or PPP Watchdog process for OS/2 and TCP/IP.
---------------------------------------------------------------
Copyright (c) Secant Technologies, 1995
Author: Nick Knight (nick@secant.com)
Purpose: to help keep you connected to your provider by automatically
attempting to reconnect after no response from an IP.
ALSO: will now work in the other direction, for systems that offer
a "dial in" connection for a remote PC. Can restart an
auto-answer SLIP process if the client is no longer
responding or never fully connects.
Programatically "pings" a specified internet address every x
minutes. If the ping fails, finds the OS/2 session handle of
the Internet connection executable (e.g., "Slip.exe"). If found,
that session is killed, and a batch command file is started that
will attempt to reconnect.
Compiled with BC++ for OS/2 v2.0, linked with the IBM TCP/IP
toolkit.
HOW IT WORKS
============
ICWatch accepts parameters from the command line. The first is the
Internet address to "test" periodically via "ping". The second is
the minutes to delay between tests, defaulting to 5. The third is
the EXE used for your connection services. This defaults to
SLIP.EXE.
ICWatch starts and immediately sleeps for the specified delay time.
This allows a "boot up" connection to be made before pinging.
It then attempts to ping the given address 10 times. If any of the
pings succeeds, it sleeps and waits for the next period. If it fails
all tests, it delays for 5 seconds and pings 10 more times. If ALL
pings fail, it attempts a connection restart.
OLD WAY:
When a "restart" is called for, ICWatch makes use of the OS/2 PSTAT
utility to create a text log of processes. I could not find a
proper call or procedure for doing this programatically. ICWatch
then scans the log file for the pertainent EXE file (ignoring paths,
only the base file name is used, e.g., "SLIP.EXE"). If found,
it extracts the process ID and calls DOSKillProcess on this ID.
NEW WAY:
When a "restart" is called for, ICWatch makes use of the an
"undocumented" call to get a list of all running executables
and their associated process id's. Thank you, Frank Mena, for
documenting this undocumented call for me :). The check for a
matching executable name ignores any prefix path UNLESS you specify
a full path on the command line. For example, defaulting the exe
name OR specifying Slip.Exe on the command line will match the file
name "c:\tcpip\bin\slip.exe". Specifying "\slip.exe" will not match
anything; if you're going to specify a path, it must be COMPLETE.
If an error occurs, ICWatch reports this and goes to sleep until the
next check. If the KILL succeeds, ICWatch delays 10 seconds to make
sure the KILL completes, then starts a new command line session,
invoking the batch file "reslip" (no directory specified). It then
sleeps and will check again in the specified number of minutes.
HINTS: Use the same or a similar batch file to start SLIP originally.
To get rid of the SLIP session and its command shell, a batch file
with an "EXIT" at the end works well. For example, the reslip.cmd
I use looks like:
--------------------------------------------
/# <- REXX comments here, converted for compilation
#/
'@echo off'
say 'Reconnecting on ' ||DATE()||' at '||TIME()
'echo Reconnecting on ' ||DATE()||' at '||TIME()|| '>>slip.log'
'slip'
'exit'
--------------------------------------------
NOTE that we log all booting and SLIP restart utility to a log.
REXX is used for this batch file, simply to format the date and
time nicely. The file could simple consist of the line "slip"
and then "exit".
USING ICWATCH AS A CLIENT CONNECTION WATCHDOG
=============================================
We set up a machine to allow us to "dial in" to our network from
on-the-road or from home. The problem was that SLIP, once it
connects, doesn't automatically reset itself for the "next"
caller. IC Watch can now remedy this problem, too!
First, IC Watch should not be running without a connection established.
So, step one is to have the REXX file used to control the "connect"
("autoans.cmd", for example) start ICWatch sometime early in the
handshaking process. This insures a reset if the connection fails. You
give ICWatch the IP address of the guest connection, and a NEGATIVE
delay time. The negative value tells ICWatch it's being invoked "on
demand" from a connection script; the absolute value of this number is
used as the delay interval. ICWatch waits, then starts periodically
pinging the given address. If all pings fail, the "reslip" command is
invoked after killing the specified executable process ("Slip.exe", by
default). In this mode, ICWatch then exits, allowing the system to
await the next caller. NOTE that care must be taken within the
REXX script to check for timeouts and invalid values. Simply add the
line:
'start /min icwatch whatever.com -1 slip.exe'
immediately before th EXIT line of your SLIp attach script (or whatever
REXX script controls your connection).
Change Log
----------
07/14/95 - v1.01. Modified pstat log parser to properly handle
non-SLIP.EXE executable names.
07/16/95 - v1.02. Removed incorrect "log parsing" error message.
07/20/95 - v1.03. The test for named EXE was case sensitive.
Now it isn't.
08/11/95 - v1.1 Minutes Delay can now be negative, causing a
wait of abs(delay), but telling icwatch to EXIT
after restarting slip. Great for invoking icwatch
from within a SLIP-server auto-answer slip (host
side slip connection for a dial-on connection).
Finished code to do process-id finding internally.
Left old code #def'd out, in case DosQProc() breaks
anytime in the future. New code does not require
pstat and does not parse a log or open files.
SOURCE CODE? Simply ask. email me at nick@secant.com.