home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / tcpiptk / rpc / rawex.c < prev    next >
Text File  |  1999-05-11  |  4KB  |  109 lines

  1. /********************************************************copyrite.xic********/
  2. /*                                                                          */
  3. /*   Licensed Materials - Property of IBM                                   */
  4. /*   IBM TCP/IP for OS/2                                                    */
  5. /*   (C) Copyright IBM Corporation. 1990,1991.                              */
  6. /*                                                                          */
  7. /*   All rights reserved.                                                   */
  8. /*                                                                          */
  9. /*   US Government Users Restricted Rights -                                */
  10. /*   Use, duplication or disclosure restricted by GSA ADP Schedule          */
  11. /*   Contract with IBM Corp.                                                */
  12. /*                                                                          */
  13. /*--------------------------------------------------------------------------*/
  14. /*                                                                          */
  15. /*  DISCLAIMER OF WARRANTIES.  The following [enclosed] code is             */
  16. /*  sample code created by IBM Corporation. This sample code is not         */
  17. /*  part of any standard or IBM product and is provided to you solely       */
  18. /*  for  the purpose of assisting you in the development of your            */
  19. /*  applications.  The code is provided "AS IS", without                    */
  20. /*  warranty of any kind.  IBM shall not be liable for any damages          */
  21. /*  arising out of your use of the sample code, even if they have been      */
  22. /*  advised of the possibility of such damages.                             */
  23. /*--------------------------------------------------------------------------*/
  24. /*RAWEX*/
  25. /* AN EXAMPLE OF THE RAW CLIENT/SERVER USAGE */
  26. /* PORTMAPPER MUST BE RUNNING */
  27.  
  28.  
  29. #include <rpc/rpctypes.h>
  30. #include <rpc/rpc.h>
  31. #include <stdio.h>
  32. #include <sys\socket.h>
  33. #include <string.h>
  34. #include <netdb.h>
  35.  
  36.  
  37. #define rawprog ((u_long)150104)
  38. #define rawvers ((u_long)1)
  39. #define rawproc ((u_long)1)
  40.  
  41. extern enum clnt_stat clntraw_call();
  42. extern void raw2();
  43.  
  44. main(argc,argv)
  45. int argc;
  46. char *argv[];
  47. {
  48.    SVCXPRT *transp;
  49.    struct hostent *hp;
  50.    struct timeval pertry_timeout, total_timeout;
  51.    struct sockaddr_in server_addr;
  52.    int bout,in;
  53.    register CLIENT *clnt;
  54.    enum clnt_stat cs;
  55.    int addrlen, sock;
  56.  
  57.    if(argc!=2) {
  58.      printf("usage:  RAWEX integer\n");
  59.      exit(-1);
  60.    }
  61.    in = atoi(argv[1]);
  62.    sock = RPC_ANYSOCK;
  63.    transp = svcraw_create();
  64.    if (transp == NULL) {
  65.       fprintf(stderr, "can't create an RPC server transport\n");
  66.       exit(-1);
  67.    }
  68.    pmap_unset(rawprog, rawvers);
  69.    if (!svc_register(transp,rawprog,rawvers,raw2, 0)) {
  70.       fprintf(stderr, "can't register service\n");
  71.       exit(-1);
  72.    }
  73.  
  74.    xprt_register(transp);
  75.  
  76.    if ((clnt = clntraw_create(rawprog, rawvers)) == NULL ) {
  77.       clnt_pcreateerror("clntudp_create");
  78.       exit(-1);
  79.    }
  80.    total_timeout.tv_sec = 60;
  81.    total_timeout.tv_usec = 0;
  82.    printf("Argument:  %d\n",in);
  83.    cs=clnt_call(clnt,rawproc,xdr_int,
  84.                 (char *)&in,xdr_int,(char *)&bout,total_timeout);
  85.    printf("Result:  %d",bout);
  86.    if(cs!=0) {
  87.       clnt_perror(clnt,"Client call failed");
  88.       exit(1);
  89.    }
  90.    exit(0);
  91. }
  92.  
  93. void raw2(rqstp,transp)
  94.    struct svc_req *rqstp;
  95.    SVCXPRT *transp;
  96. {
  97.    int in,out;
  98.    if (rqstp->rq_proc=rawproc) {
  99.    svc_getargs(transp,xdr_int,&in);
  100.    printf("Received:  %d\n",in);
  101.    out=in;
  102.    printf("Sent:  %d\n",out);
  103.    if (!svc_sendreply(transp, xdr_int,(char * )&out)) {
  104.       printf("Can't reply to RPC call.\n");
  105.       exit(1);
  106.    }
  107.    }
  108. }
  109.