]> git.neil.brown.name Git - portmap.git/blob - pmap_dump.c
Clean up more warnings.
[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 #ifndef lint
9 static __attribute__((__used__)) char
10 sccsid[] = "@(#) pmap_dump.c 1.1 92/06/11 22:53:15";
11 #endif
12
13 #include <stdio.h>
14 #include <sys/types.h>
15 #ifdef SYSV40
16 #include <netinet/in.h>
17 #include <rpc/rpcent.h>
18 #else
19 #include <netdb.h>
20 #endif
21 #include <rpc/rpc.h>
22 #include <rpc/pmap_clnt.h>
23 #include <rpc/pmap_prot.h>
24
25 static char *protoname(u_long proto);
26
27 int
28 main(int argc, char **argv)
29 {
30     struct sockaddr_in addr;
31     register struct pmaplist *list;
32     register struct rpcent *rpc;
33
34     get_myaddress(&addr);
35
36     for (list = pmap_getmaps(&addr); list; list = list->pml_next) {
37         rpc = getrpcbynumber((int) list->pml_map.pm_prog);
38         printf("%10lu %4lu %5s %6lu  %s\n",
39                list->pml_map.pm_prog,
40                list->pml_map.pm_vers,
41                protoname(list->pml_map.pm_prot),
42                list->pml_map.pm_port,
43                rpc ? rpc->r_name : "");
44     }
45     return (fclose(stdout) ? (perror(argv[0]), 1) : 0);
46 }
47
48 static char *protoname(u_long proto)
49 {
50     static char buf[BUFSIZ];
51
52     switch (proto) {
53     case IPPROTO_UDP:
54         return ("udp");
55     case IPPROTO_TCP:
56         return ("tcp");
57     default:
58         sprintf(buf, "%lu", proto);
59         return (buf);
60     }
61 }