"Fossies" - the Fresh Open Source Software Archive

Member "coda-6.9.5/coda-src/smon2/rpc2ping.c" (20 Jul 2007, 3037 Bytes) of package /linux/misc/old/coda-6.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "rpc2ping.c" see the Fossies "Dox" file reference documentation.

    1 /* BLURB gpl
    2 
    3                            Coda File System
    4                               Release 6
    5 
    6           Copyright (c) 1987-2003 Carnegie Mellon University
    7                   Additional copyrights listed below
    8 
    9 This  code  is  distributed "AS IS" without warranty of any kind under
   10 the terms of the GNU General Public Licence Version 2, as shown in the
   11 file  LICENSE.  The  technical and financial  contributors to Coda are
   12 listed in the file CREDITS.
   13 
   14                         Additional copyrights
   15                            none currently
   16 
   17 #*/
   18 
   19 /*
   20  * Very simple program to monitor Coda servers, it only sets up an rpc2
   21  * connection, so it won't catch internal server problems. But it does
   22  * detect a crashed server.
   23  * 
   24  *   Jan Harkes, September 1999
   25  */
   26 
   27 #include <sys/time.h>
   28 #include <stdio.h>
   29 #include <stdlib.h>
   30 #include <lwp/lwp.h>
   31 #include <rpc2/rpc2.h>
   32 #include <coda_string.h>
   33 #include <coda_getservbyname.h>
   34 
   35 void Initialize(void)
   36 {
   37     RPC2_Options options;
   38     PROCESS pid;
   39     struct timeval tv;
   40     long rc;
   41 
   42     /* initialize the subsystems LWP/RPC */
   43     rc = LWP_Init(LWP_VERSION, LWP_NORMAL_PRIORITY, &pid);
   44     if (rc != LWP_SUCCESS) {
   45     printf("LWP_Init() failed\n");
   46     exit(-1);
   47     }
   48 
   49     tv.tv_sec = 15;
   50     tv.tv_usec = 0;
   51 
   52     memset(&options, 0, sizeof(options));
   53     options.Flags = RPC2_OPTION_IPV6;
   54 
   55     rc = RPC2_Init(RPC2_VERSION, &options, NULL, -1, &tv);
   56     if (rc != LWP_SUCCESS) {
   57     printf("RPC_Init() failed\n");
   58     exit(-1);
   59     }
   60 }
   61 
   62 long Bind(char *host, short port, long subsys, RPC2_Handle *cid)
   63 {
   64     RPC2_HostIdent   hostid;
   65     RPC2_PortIdent   portid;
   66     RPC2_SubsysIdent subsysid;
   67     RPC2_BindParms   bindparms;
   68 
   69     /* Initialize connection stuff */
   70     hostid.Tag = RPC2_HOSTBYNAME;
   71     strcpy(hostid.Value.Name, host);
   72 
   73     portid.Tag = RPC2_PORTBYINETNUMBER;
   74     portid.Value.InetPortNumber = htons(port);
   75 
   76     subsysid.Tag = RPC2_SUBSYSBYID;
   77     subsysid.Value.SubsysId= subsys;
   78 
   79     bindparms.SideEffectType = 0;
   80     bindparms.SecurityLevel = RPC2_OPENKIMONO;
   81     bindparms.ClientIdent = NULL;
   82 
   83     return RPC2_NewBinding(&hostid, &portid, &subsysid, &bindparms, cid);
   84 }
   85 
   86 int main(int argc, char *argv[])
   87 {
   88     RPC2_Handle cid;
   89     long    subsys = 1001;
   90     long        rc;
   91     char       *host;
   92     short       port;
   93 
   94     if (argc == 1)
   95         goto badargs;
   96 
   97     if (strcmp(argv[1], "-p") == 0) {
   98         if (argc < 4)
   99             goto badargs;
  100 
  101         host = argv[3];
  102         port = atoi(argv[2]);
  103     } else {
  104     struct servent *s = coda_getservbyname("codasrv", "udp");
  105         host = argv[1];
  106         port = ntohs(s->s_port);
  107     subsys = 1001; /* SUBSYS_SRV */
  108     }
  109 
  110     Initialize();
  111 
  112     rc = Bind(host, port, subsys, &cid);
  113 
  114     RPC2_Unbind(cid);
  115 
  116     if (rc != RPC2_SUCCESS) {
  117         printf("RPC2 connection to %s:%d failed with %s.\n",
  118                host, port, RPC2_ErrorMsg(rc));
  119         exit(2);
  120     }
  121     
  122     printf("RPC2 connection to %s:%d successful.\n", host, port);
  123     exit(0);
  124 
  125 badargs:
  126     printf("Usage %s [-p port] hostname\n", argv[0]);
  127     exit(-1);
  128 }
  129