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

  1. /*
  2.  *      $Id: pmap_getport.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_getport.c    2.2 88/08/01 4.0 RPCSRC */
  12. #if !defined(lint) && defined(SCCSIDS)
  13. static char sccsid[] = "@(#)pmap_getport.c 1.9 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. #include <net/if.h>
  26.  
  27. static struct timeval timeout = { 5, 0 };
  28. static struct timeval tottimeout = { 60, 0 };
  29.  
  30. /*
  31.  * Find the mapped port for program,version.
  32.  * Calls the pmap service remotely to do the lookup.
  33.  * Returns 0 if no map exists.
  34.  */
  35. u_short
  36. pmap_getport(address, program, version, protocol)
  37.     struct sockaddr_in *address;
  38.     u_long program;
  39.     u_long version;
  40.     u_int protocol;
  41. {
  42.     u_short port = 0;
  43.     int socket = -1;
  44.     register CLIENT *client;
  45.     struct pmap parms;
  46.  
  47.     address->sin_port = htons(PMAPPORT);
  48.     client = clntudp_bufcreate(address, PMAPPROG,
  49.         PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
  50.     if (client != (CLIENT *)NULL) {
  51.         parms.pm_prog = program;
  52.         parms.pm_vers = version;
  53.         parms.pm_prot = protocol;
  54.         parms.pm_port = 0;  /* not needed or used */
  55.         if (CLNT_CALL(client, PMAPPROC_GETPORT, xdr_pmap, &parms,
  56.             xdr_u_short, &port, tottimeout) != RPC_SUCCESS){
  57.             rpc_createerr.cf_stat = RPC_PMAPFAILURE;
  58.             clnt_geterr(client, &rpc_createerr.cf_error);
  59.         } else if (port == 0) {
  60.             rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
  61.         }
  62.         CLNT_DESTROY(client);
  63.     }
  64. #ifdef AMITCP
  65.     (void)CloseSocket(socket);
  66. #else
  67.     (void)close(socket);
  68. #endif
  69.     address->sin_port = 0;
  70.     return (port);
  71. }
  72.