home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / icwatch.zip / ICWATCH.DOC < prev    next >
Text File  |  1995-08-23  |  6KB  |  145 lines

  1.  
  2. ICWatch.c - Slip or PPP Watchdog process for OS/2 and TCP/IP.
  3. ---------------------------------------------------------------
  4.  
  5. Copyright (c) Secant Technologies, 1995
  6. Author: Nick Knight (nick@secant.com)
  7.  
  8. Purpose: to help keep you connected to your provider by automatically
  9.      attempting to reconnect after no response from an IP.
  10.  
  11. ALSO:     will now work in the other direction, for systems that offer
  12.      a "dial in" connection for a remote PC.  Can restart an
  13.      auto-answer SLIP process if the client is no longer
  14.      responding or never fully connects.
  15.  
  16. Programatically "pings" a specified internet address every x 
  17. minutes.  If the ping fails, finds the OS/2 session handle of
  18. the Internet connection executable (e.g., "Slip.exe").  If found,
  19. that session is killed, and a batch command file is started that
  20. will attempt to reconnect.
  21.     
  22. Compiled with BC++ for OS/2 v2.0, linked with the IBM TCP/IP
  23. toolkit.
  24.     
  25.  
  26. HOW IT WORKS
  27. ============
  28. ICWatch accepts parameters from the command line.  The first is the
  29. Internet address to "test" periodically via "ping".  The second is
  30. the minutes to delay between tests, defaulting to 5.  The third is
  31. the EXE used for your connection services.  This defaults to
  32. SLIP.EXE.
  33.  
  34. ICWatch starts and immediately sleeps for the specified delay time.
  35. This allows a "boot up" connection to be made before pinging. 
  36. It then attempts to ping the given address 10 times.  If any of the
  37. pings succeeds, it sleeps and waits for the next period.  If it fails
  38. all tests, it delays for 5 seconds and pings 10 more times.  If ALL
  39. pings fail, it attempts a connection restart.     
  40.  
  41. OLD WAY:
  42.  
  43. When a "restart" is called for, ICWatch makes use of the OS/2 PSTAT
  44. utility to create a text log of processes.  I could not find a
  45. proper call or procedure for doing this programatically.  ICWatch
  46. then scans the log file for the pertainent EXE file (ignoring paths,
  47. only the base file name is used, e.g., "SLIP.EXE").  If found,
  48. it extracts the process ID and calls DOSKillProcess on this ID.
  49.  
  50. NEW WAY:
  51.  
  52. When a "restart" is called for, ICWatch makes use of the an
  53. "undocumented" call to get a list of all running executables
  54. and their associated process id's.  Thank you, Frank Mena, for
  55. documenting this undocumented call for me :).  The check for a
  56. matching executable name ignores any prefix path UNLESS you specify
  57. a full path on the command line.  For example, defaulting the exe
  58. name OR specifying Slip.Exe on the command line will match the file
  59. name "c:\tcpip\bin\slip.exe".  Specifying "\slip.exe" will not match
  60. anything; if you're going to specify a path, it must be COMPLETE.
  61.  
  62. If an error occurs, ICWatch reports this and goes to sleep until the
  63. next check.  If the KILL succeeds, ICWatch delays 10 seconds to make
  64. sure the KILL completes, then starts a new command line session,
  65. invoking the batch file "reslip" (no directory specified).  It then
  66. sleeps and will check again in the specified number of minutes.
  67.  
  68. HINTS:    Use the same or a similar batch file to start SLIP originally.
  69. To get rid of the SLIP session and its command shell, a batch file
  70. with an "EXIT" at the end works well.  For example, the reslip.cmd
  71. I use looks like:
  72.  
  73. --------------------------------------------
  74.     /#        <- REXX comments here, converted for compilation
  75.     #/
  76.     '@echo off'
  77.  
  78.     say 'Reconnecting on ' ||DATE()||' at '||TIME()
  79.     'echo Reconnecting on ' ||DATE()||' at '||TIME()|| '>>slip.log'
  80.  
  81.     'slip'
  82.     'exit'
  83. --------------------------------------------
  84.  
  85. NOTE that we log all booting and SLIP restart utility to a log.  
  86. REXX is used for this batch file, simply to format the date and
  87. time nicely.  The file could simple consist of the line "slip" 
  88. and then "exit".
  89.  
  90.  
  91. USING ICWATCH AS A CLIENT CONNECTION WATCHDOG
  92. =============================================
  93.  
  94. We set up a machine to allow us to "dial in" to our network from
  95. on-the-road or from home.  The problem was that SLIP, once it
  96. connects, doesn't automatically reset itself for the "next"
  97. caller.  IC Watch can now remedy this problem, too!
  98.  
  99. First, IC Watch should not be running without a connection established.  
  100. So, step one is to have the REXX file used to control the "connect" 
  101. ("autoans.cmd", for example) start ICWatch sometime early in the 
  102. handshaking process.  This insures a reset if the connection fails. You 
  103. give ICWatch the IP address of the guest connection, and a NEGATIVE 
  104. delay time.  The negative value tells ICWatch it's being invoked "on 
  105. demand" from a connection script; the absolute value of this number is 
  106. used as the delay interval.  ICWatch waits, then starts periodically 
  107. pinging the given address.  If all pings fail, the "reslip" command is 
  108. invoked after killing the specified executable process ("Slip.exe", by 
  109. default).  In this mode, ICWatch then exits, allowing the system to 
  110. await the next caller.    NOTE that care must be taken within the 
  111. REXX script to check for timeouts and invalid values.  Simply add the
  112. line:
  113.     
  114.     'start /min icwatch whatever.com -1 slip.exe'
  115.     
  116. immediately before th EXIT line of your SLIp attach script (or whatever
  117. REXX script controls your connection).
  118.     
  119.  
  120. Change Log                         
  121. ----------
  122.  
  123. 07/14/95 - v1.01.  Modified pstat log parser to properly handle
  124.            non-SLIP.EXE executable names.
  125.  
  126. 07/16/95 - v1.02.  Removed incorrect "log parsing" error message.           
  127.  
  128. 07/20/95 - v1.03.  The test for named EXE was case sensitive.
  129.            Now it isn't.
  130.  
  131. 08/11/95 - v1.1    Minutes Delay can now be negative, causing a
  132.            wait of abs(delay), but telling icwatch to EXIT
  133.            after restarting slip.  Great for invoking icwatch
  134.            from within a SLIP-server auto-answer slip (host
  135.            side slip connection for a dial-on connection).
  136.            
  137.            Finished code to do process-id finding internally.
  138.            Left old code #def'd out, in case DosQProc() breaks
  139.            anytime in the future.  New code does not require
  140.            pstat and does not parse a log or open files.
  141.  
  142.  
  143. SOURCE CODE?  Simply ask. email me at nick@secant.com.
  144.  
  145.