home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / winsock / kalive / kalive.c next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  1.1 KB  |  61 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <winsock.h>
  4.  
  5.  
  6.  void disp_help()
  7.  
  8.   {
  9.  
  10.    printf("\nKeep alive program V 1.0 by L. Kahn (C) 1994\n");
  11.    printf("_______________________________________________\n\n");
  12.    printf("This program keeps a connection alive by \n");
  13.    printf("continually pinging a specific host name\n");
  14.    printf("every XXX seconds\n");
  15.  
  16.    printf("Syntax: keepalive hostname timeout\n");
  17.    printf("WHERE: hostname is the name or ip address of a host.\n");
  18.    printf("       and timeout is in seconds.\n");
  19.  
  20.   }
  21.  
  22.  
  23.   void main(argc,argv)
  24.   
  25.   int argc;
  26.   char **argv;
  27.    
  28.   {
  29.  
  30.  
  31.   char command[250];
  32.   int rv = 0;
  33.   int timeout = 0;
  34.    
  35.    if (argc != 3)
  36.      disp_help();
  37.  
  38.    else
  39.    {
  40.      /* ok assume second arg is host name */
  41.   
  42.           timeout = atoi(argv[2]) * 1000;
  43.           strcpy(command,"ping ");
  44.           strcat(command,argv[1]);
  45.     
  46.     while (TRUE)
  47.           {
  48.           rv = system(command);
  49.           printf("\nSleeping for %d seconds.\n",timeout/1000);
  50.           Sleep(timeout);
  51.           }
  52.  
  53.      printf("\n");
  54.      fflush(stdout);
  55.  
  56.              } /* end of else */
  57.  
  58.   } /* end of main */          
  59.  
  60.  
  61.