1 /* Copyright © 2003 Russ Cox, MIT; see /sys/src/libsunrpc/COPYING */
13 fprint(2, "usage: portmap address [cmd]\n"
16 "\tset prog vers proto port\n"
17 "\tunset prog vers proto port\n"
18 "\tgetport prog vers proto\n"
19 "\tdump (default)\n");
20 threadexitsall("usage");
24 portCall(SunCall *c, PortCallType type)
26 c->rpc.prog = PortProgram;
27 c->rpc.vers = PortVersion;
28 c->rpc.proc = type>>1;
29 c->rpc.iscall = !(type&1);
41 memset(&tx, 0, sizeof tx);
42 portCall(&tx.call, PortCallTNull);
44 memset(&rx, 0, sizeof rx);
45 portCall(&rx.call, PortCallRNull);
47 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
57 memset(&tx, 0, sizeof tx);
58 portCall(&tx.call, PortCallTSet);
59 tx.map.prog = strtol(argv[0], 0, 0);
60 tx.map.vers = strtol(argv[1], 0, 0);
61 tx.map.prot = strtol(argv[2], 0, 0);
62 tx.map.port = strtol(argv[3], 0, 0);
64 memset(&rx, 0, sizeof rx);
65 portCall(&rx.call, PortCallRSet);
67 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
80 memset(&tx, 0, sizeof tx);
81 portCall(&tx.call, PortCallTUnset);
82 tx.map.prog = strtol(argv[0], 0, 0);
83 tx.map.vers = strtol(argv[1], 0, 0);
84 tx.map.prot = strtol(argv[2], 0, 0);
85 tx.map.port = strtol(argv[3], 0, 0);
87 memset(&rx, 0, sizeof rx);
88 portCall(&rx.call, PortCallRUnset);
90 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
103 memset(&tx, 0, sizeof tx);
104 portCall(&tx.call, PortCallTGetport);
105 tx.map.prog = strtol(argv[0], 0, 0);
106 tx.map.vers = strtol(argv[1], 0, 0);
107 tx.map.prot = strtol(argv[2], 0, 0);
109 memset(&rx, 0, sizeof rx);
110 portCall(&rx.call, PortCallRGetport);
112 if(sunClientRpc(client, 0, &tx.call, &rx.call, nil) < 0)
115 print("%d\n", rx.port);
129 memset(&tx, 0, sizeof tx);
130 portCall(&tx.call, PortCallTDump);
132 memset(&rx, 0, sizeof rx);
133 portCall(&rx.call, PortCallRDump);
135 if(sunClientRpc(client, 0, &tx.call, &rx.call, &p) < 0)
138 for(i=0, m=rx.map; i<rx.nmap; i++, m++)
139 print("%ud %ud %ud %ud\n", (uint)m->prog, (uint)m->vers, (uint)m->prot, (uint)m->port);
152 "getport", 3, tgetport,
157 threadmain(int argc, char **argv)
159 char *dflt[] = { "dump", };
172 fmtinstall('B', sunRpcFmt);
173 fmtinstall('C', sunCallFmt);
174 fmtinstall('H', encodefmt);
175 sunFmtInstall(&portProg);
177 addr = netmkaddr(argv[0], "udp", "portmap");
178 if((client = sunDial(addr)) == nil)
179 sysfatal("dial %s: %r", addr);
181 client->chatty = chatty;
182 sunClientProg(client, &portProg);
195 for(i=0; i<nelem(tab); i++){
196 if(strcmp(tab[i].cmd, cmd) == 0){
197 if(tab[i].narg != argc)