2
#include <netinet/in.h>
3
#include <asm/byteorder.h> /* __constant_hton* */
25
static struct portmap_call call = {
26
.rpc.program = __constant_htonl(RPC_PMAP_PROGRAM),
27
.rpc.prog_vers = __constant_htonl(RPC_PMAP_VERSION),
28
.rpc.proc = __constant_htonl(PMAP_PROC_GETPORT),
31
__u32 portmap(__u32 server, __u32 program, __u32 version, __u32 proto)
33
struct portmap_reply reply;
38
if ((clnt = tcp_client(server, RPC_PMAP_PORT, 0)) == NULL) {
39
if ((clnt = udp_client(server, RPC_PMAP_PORT, 0)) == NULL) {
44
call.program = htonl(program);
45
call.version = htonl(version);
46
call.proto = htonl(proto);
48
rpc.call = (struct rpc_call *) &call;
49
rpc.call_len = sizeof(call);
50
rpc.reply = (struct rpc_reply *) &reply;
51
rpc.reply_len = sizeof(reply);
53
if (rpc_call(clnt, &rpc) < 0)
56
if (rpc.reply_len < sizeof(reply)) {
57
fprintf(stderr, "incomplete reply: %zu < %zu\n",
58
rpc.reply_len, sizeof(reply));
62
port = ntohl(reply.port);
65
DEBUG(("Port for %d/%d[%s]: %d\n", program, version,
66
proto == IPPROTO_TCP ? "tcp" : "udp", port));