]> git.neil.brown.name Git - portmap.git/blob - pmap_dump.c
Only fail an 'unregister' attempt if nothing can be unregistered.
[portmap.git] / pmap_dump.c
1  /*
2   * pmap_dump - dump portmapper table in format readable by pmap_set
3   * 
4   * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
5   * Computing Science, Eindhoven University of Technology, The Netherlands.
6   */
7
8 #include <stdio.h>
9 #include <sys/types.h>
10 #ifdef SYSV40
11 #include <netinet/in.h>
12 #include <rpc/rpcent.h>
13 #else
14 #include <netdb.h>
15 #endif
16 #include <rpc/rpc.h>
17 #include <rpc/pmap_clnt.h>
18 #include <rpc/pmap_prot.h>
19
20 static const char *protoname(u_long proto)
21 {
22     static char buf[BUFSIZ];
23
24     switch (proto) {
25     case IPPROTO_UDP:
26         return ("udp");
27     case IPPROTO_TCP:
28         return ("tcp");
29     default:
30         sprintf(buf, "%lu", proto);
31         return (buf);
32     }
33 }
34
35 int
36 main(int argc, char **argv)
37 {
38     struct sockaddr_in addr;
39     struct pmaplist *list;
40     struct rpcent *rpc;
41
42     memset(&addr, 0, sizeof(addr));
43     addr.sin_family = AF_INET;
44     addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
45     addr.sin_port = htons(PMAPPORT);
46
47     for (list = pmap_getmaps(&addr); list; list = list->pml_next) {
48         rpc = getrpcbynumber((int) list->pml_map.pm_prog);
49         printf("%10lu %4lu %5s %6lu  %s\n",
50                list->pml_map.pm_prog,
51                list->pml_map.pm_vers,
52                protoname(list->pml_map.pm_prot),
53                list->pml_map.pm_port,
54                rpc ? rpc->r_name : "");
55     }
56     return (fclose(stdout) ? (perror(argv[0]), 1) : 0);
57 }
58