home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp-sdk / src / rpclib / pmap_clnt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-29  |  2.4 KB  |  102 lines

  1. /*
  2.  *      $Id: pmap_clnt.c,v 4.2 1994/09/29 23:48:50 jraja Exp $
  3.  *
  4.  *      Client interface to pmap rpc service.
  5.  *
  6.  *      Copyright © 1994 AmiTCP/IP Group,
  7.  *                       Network Solutions Development Inc.
  8.  *                       All rights reserved. 
  9.  */
  10.  
  11. /* @(#)pmap_clnt.c    2.2 88/08/01 4.0 RPCSRC */
  12. #if !defined(lint) && defined(SCCSIDS)
  13. static char sccsid[] = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
  14. #endif
  15.  
  16. /*
  17.  * Copyright (C) 1984, Sun Microsystems, Inc.
  18.  */
  19.  
  20. #include <sys/param.h>
  21. #include <rpc/rpc.h>
  22. #include <rpc/pmap_prot.h>
  23. #include <rpc/pmap_clnt.h>
  24. #include <sys/socket.h>
  25.  
  26. static struct timeval timeout = { 5, 0 };
  27. static struct timeval tottimeout = { 60, 0 };
  28.  
  29. /*
  30.  * Set a mapping between program,version and port.
  31.  * Calls the pmap service remotely to do the mapping.
  32.  */
  33. bool_t
  34. pmap_set(program, version, protocol, port)
  35.     u_long program;
  36.     u_long version;
  37.     int protocol;
  38.     u_short port;
  39. {
  40.     struct sockaddr_in myaddress;
  41.     int socket = -1;
  42.     register CLIENT *client;
  43.     struct pmap parms;
  44.     bool_t rslt;
  45.  
  46.     get_myaddress(&myaddress);
  47.     client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
  48.         timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
  49.     if (client == (CLIENT *)NULL)
  50.         return (FALSE);
  51.     parms.pm_prog = program;
  52.     parms.pm_vers = version;
  53.     parms.pm_prot = protocol;
  54.     parms.pm_port = port;
  55.     if (CLNT_CALL(client, PMAPPROC_SET, xdr_pmap, &parms, xdr_bool, &rslt,
  56.         tottimeout) != RPC_SUCCESS) {
  57.         clnt_perror(client, "Cannot register service");
  58.         return (FALSE);
  59.     }
  60.     CLNT_DESTROY(client);
  61. #ifdef AMITCP
  62.     (void)CloseSocket(socket);
  63. #else
  64.     (void)close(socket);
  65. #endif
  66.     return (rslt);
  67. }
  68.  
  69. /*
  70.  * Remove the mapping between program,version and port.
  71.  * Calls the pmap service remotely to do the un-mapping.
  72.  */
  73. bool_t
  74. pmap_unset(program, version)
  75.     u_long program;
  76.     u_long version;
  77. {
  78.     struct sockaddr_in myaddress;
  79.     int socket = -1;
  80.     register CLIENT *client;
  81.     struct pmap parms;
  82.     bool_t rslt;
  83.  
  84.     get_myaddress(&myaddress);
  85.     client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
  86.         timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
  87.     if (client == (CLIENT *)NULL)
  88.         return (FALSE);
  89.     parms.pm_prog = program;
  90.     parms.pm_vers = version;
  91.     parms.pm_port = parms.pm_prot = 0;
  92.     CLNT_CALL(client, PMAPPROC_UNSET, xdr_pmap, &parms, xdr_bool, &rslt,
  93.         tottimeout);
  94.     CLNT_DESTROY(client);
  95. #ifdef AMITCP
  96.     (void)CloseSocket(socket);
  97. #else
  98.     (void)close(socket);
  99. #endif
  100.     return (rslt);
  101. }
  102.