12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #if 0
- static char sccsid[] = "@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
- #endif
- #include <stdbool.h>
- #include <unistd.h>
- #include <rpc/rpc.h>
- #include <rpc/pmap_prot.h>
- #include <rpc/pmap_clnt.h>
- static const struct timeval timeout =
- {5, 0};
- static const struct timeval tottimeout =
- {60, 0};
- u_short
- pmap_getport (struct sockaddr_in *address, u_long program, u_long version,
- u_int protocol)
- {
- u_short port = 0;
- int _socket = -1;
- CLIENT *client;
- struct pmap parms;
- address->sin_port = htons (PMAPPORT);
- client = clntudp_bufcreate (address, PMAPPROG,
- PMAPVERS, timeout, &_socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
- if (client != (CLIENT *) NULL)
- {
- struct rpc_createerr *ce = &get_rpc_createerr ();
- parms.pm_prog = program;
- parms.pm_vers = version;
- parms.pm_prot = protocol;
- parms.pm_port = 0;
- if (CLNT_CALL (client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap,
- (caddr_t)&parms, (xdrproc_t)xdr_u_short,
- (caddr_t)&port, tottimeout) != RPC_SUCCESS)
- {
- ce->cf_stat = RPC_PMAPFAILURE;
- clnt_geterr (client, &ce->cf_error);
- }
- else if (port == 0)
- {
- ce->cf_stat = RPC_PROGNOTREGISTERED;
- }
- CLNT_DESTROY (client);
- }
-
- address->sin_port = 0;
- return port;
- }
- libc_hidden_def(pmap_getport)
|