Commit | Line | Data |
---|---|---|
984263bc MD |
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 | ||
1de703da MD |
8 | /* |
9 | * @(#) pmap_dump.c 1.1 92/06/11 22:53:15 | |
10 | * $FreeBSD: src/usr.sbin/portmap/pmap_dump/pmap_dump.c,v 1.6 2000/01/15 23:08:30 brian Exp $ | |
2d8a3be7 | 11 | * $DragonFly: src/usr.sbin/portmap/pmap_dump/pmap_dump.c,v 1.3 2003/11/03 19:31:40 eirikn Exp $ |
1de703da | 12 | */ |
984263bc MD |
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 | ||
2d8a3be7 | 25 | static const char *protoname(u_long); |
984263bc MD |
26 | |
27 | int | |
28 | main(argc, argv) | |
29 | int argc; | |
30 | char **argv; | |
31 | { | |
32 | struct sockaddr_in addr; | |
33 | register struct pmaplist *list; | |
34 | register struct rpcent *rpc; | |
35 | ||
36 | get_myaddress(&addr); | |
37 | ||
38 | for (list = pmap_getmaps(&addr); list; list = list->pml_next) { | |
39 | rpc = getrpcbynumber((int) list->pml_map.pm_prog); | |
40 | printf("%10lu %4lu %5s %6lu %s\n", | |
41 | list->pml_map.pm_prog, | |
42 | list->pml_map.pm_vers, | |
43 | protoname(list->pml_map.pm_prot), | |
44 | list->pml_map.pm_port, | |
45 | rpc ? rpc->r_name : ""); | |
46 | } | |
47 | #undef perror | |
48 | return (fclose(stdout) ? (perror(argv[0]), 1) : 0); | |
49 | } | |
50 | ||
51 | static const char * | |
52 | protoname(proto) | |
53 | u_long proto; | |
54 | { | |
55 | static char buf[BUFSIZ]; | |
56 | ||
57 | switch (proto) { | |
58 | case IPPROTO_UDP: | |
59 | return ("udp"); | |
60 | case IPPROTO_TCP: | |
61 | return ("tcp"); | |
62 | default: | |
63 | sprintf(buf, "%lu", proto); | |
64 | return (buf); | |
65 | } | |
66 | } |