Initial import from FreeBSD RELENG_4:
[games.git] / usr.sbin / portmap / pmap_dump / 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 #if 0
10 static char sccsid[] = "@(#) pmap_dump.c 1.1 92/06/11 22:53:15";
11 #endif
12 static const char rcsid[] =
13   "$FreeBSD: src/usr.sbin/portmap/pmap_dump/pmap_dump.c,v 1.6 2000/01/15 23:08:30 brian Exp $";
14 #endif
15
16 #include <stdio.h>
17 #include <sys/types.h>
18 #ifdef SYSV40
19 #include <netinet/in.h>
20 #include <rpc/rpcent.h>
21 #else
22 #include <netdb.h>
23 #endif
24 #include <rpc/rpc.h>
25 #include <rpc/pmap_clnt.h>
26 #include <rpc/pmap_prot.h>
27
28 static const char *protoname __P((u_long));
29
30 int
31 main(argc, argv)
32     int argc;
33     char **argv;
34 {
35     struct sockaddr_in addr;
36     register struct pmaplist *list;
37     register struct rpcent *rpc;
38
39     get_myaddress(&addr);
40
41     for (list = pmap_getmaps(&addr); list; list = list->pml_next) {
42         rpc = getrpcbynumber((int) list->pml_map.pm_prog);
43         printf("%10lu %4lu %5s %6lu  %s\n",
44                list->pml_map.pm_prog,
45                list->pml_map.pm_vers,
46                protoname(list->pml_map.pm_prot),
47                list->pml_map.pm_port,
48                rpc ? rpc->r_name : "");
49     }
50 #undef perror
51     return (fclose(stdout) ? (perror(argv[0]), 1) : 0);
52 }
53
54 static const char *
55 protoname(proto)
56     u_long proto;
57 {
58     static char buf[BUFSIZ];
59
60     switch (proto) {
61     case IPPROTO_UDP:
62         return ("udp");
63     case IPPROTO_TCP:
64         return ("tcp");
65     default:
66         sprintf(buf, "%lu", proto);
67         return (buf);
68     }
69 }