home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RPCSMP.ZIP / rgs.c < prev    next >
Text File  |  1992-12-10  |  3KB  |  88 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <rpc/rpc.h>
  5. #include <rpc/pmap_pro.h>
  6. #include "rg.h"
  7.  
  8. // as we are passing a pointer to this function to svc_register, we must
  9. // declare it as _Far16 _Cdecl, and the pointers passed must be _Seg16.
  10. static void _Far16 _Cdecl messageprog_1(struct svc_req * _Seg16 rqstp, SVCXPRT * _Seg16 transp);
  11.  
  12. int main(int argc,char **argv) {
  13.         SVCXPRT *transp;
  14.  
  15.         pmap_unset(MESSAGEPROG, MESSAGEVERS);
  16.  
  17.         transp = svcudp_create(RPC_ANYSOCK);
  18.         if (transp == NULL) {
  19.                 fprintf(stderr, "cannot create udp service.\n");
  20.                 return 1;
  21.         }
  22.         if (!svc_register(transp, MESSAGEPROG, MESSAGEVERS, messageprog_1, IPPROTO_UDP)) {
  23.                 fprintf(stderr, "unable to register (MESSAGEPROG, MESSAGEVERS, udp).\n");
  24.                 return 1;
  25.         }
  26.  
  27.         transp = svctcp_create(RPC_ANYSOCK, 0, 0);
  28.         if (transp == NULL) {
  29.                 fprintf(stderr, "cannot create tcp service.\n");
  30.                 return 1;
  31.         }
  32.         if (!svc_register(transp, MESSAGEPROG, MESSAGEVERS, messageprog_1, IPPROTO_TCP)) {
  33.                 fprintf(stderr, "unable to register (MESSAGEPROG, MESSAGEVERS, tcp).\n");
  34.                 return 1;
  35.         }
  36.         svc_run();
  37.         fprintf(stderr, "svc_run returned\n");
  38.         return 1;
  39. }
  40.  
  41. static void _Far16 _Cdecl messageprog_1(struct svc_req * _Seg16 rqstp, SVCXPRT * _Seg16 transp)
  42. {
  43.         union {
  44.                 char * _Seg16 printmessage_1_arg;
  45.         } argument;
  46.         char *pch32;
  47.         char *result;
  48.         xdrproc_t xdr_argument,xdr_result;
  49.         int * (* local)(char **);
  50.  
  51.         switch (rqstp->rq_proc) {
  52.         case NULLPROC:
  53.                 svc_sendreply(transp, xdr_void, NULL);
  54.                 return;
  55.  
  56.         case PRINTMESSAGE:
  57.                 xdr_argument = xdr_wrapstring;
  58.                 xdr_result = xdr_int;
  59. //                local = (char *(*)()) printmessage_1;
  60.                 local = printmessage_2;
  61.                 break;
  62.  
  63.         default:
  64.                 svcerr_noproc(transp);
  65.                 return;
  66.         }
  67.         bzero(&argument, sizeof(argument));
  68.         if (!svc_getargs(transp, xdr_argument, &argument)) {
  69.                 svcerr_decode(transp);
  70.                 return;
  71.         }
  72. //        result = (*local)(&argument, rqstp);
  73. // Note! argument.printmessage_1_arg is a 16 bit pointer.  We must pass
  74. // a 32 bit pointer to a 32 bit pointer when we call local (printmessage_1)
  75. // so it will not do to pass (char **)&argument -- we would be passing a
  76. // 32 bit pointer to a 16 bit pointer.
  77.         pch32=argument.printmessage_1_arg;
  78.         result =(char *)((*local)((char **)&pch32));
  79.         if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
  80.                 svcerr_systemerr(transp);
  81.         }
  82.         if (!svc_freeargs(transp, xdr_argument, &argument)) {
  83.                 fprintf(stderr, "unable to free arguments\n");
  84.                 exit(1);
  85.         }
  86. }
  87.  
  88.