1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #define __FORCE_GLIBC__
- #include <features.h>
- #include <rpc/rpc.h>
- #include <rpc/pmap_prot.h>
- #include <rpc/pmap_clnt.h>
- #include <sys/socket.h>
- #include <unistd.h>
- static struct timeval timeout = { 5, 0 };
- static struct timeval tottimeout = { 60, 0 };
- u_short pmap_getport(address, program, version, protocol)
- struct sockaddr_in *address;
- u_long program;
- u_long version;
- u_int protocol;
- {
- u_short port = 0;
- int socket = -1;
- register CLIENT *client;
- struct pmap parms;
- address->sin_port = htons(PMAPPORT);
- client = clntudp_bufcreate(address, PMAPPROG,
- PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE,
- RPCSMALLMSGSIZE);
- if (client != (CLIENT *) NULL) {
- 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) {
- rpc_createerr.cf_stat = RPC_PMAPFAILURE;
- clnt_geterr(client, &rpc_createerr.cf_error);
- } else if (port == 0) {
- rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
- }
- CLNT_DESTROY(client);
- }
- (void) close(socket);
- address->sin_port = 0;
- return (port);
- }
|