File: pmap_dump.c

package info (click to toggle)
portmap 5-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 160 kB
  • ctags: 109
  • sloc: ansic: 1,048; makefile: 99; sh: 58
file content (77 lines) | stat: -rw-r--r-- 1,717 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 /*
  * pmap_dump - dump portmapper table in format readable by pmap_set
  * 
  * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
  * Computing Science, Eindhoven University of Technology, The Netherlands.
  */

#ifndef lint
static char sccsid[] = "@(#) pmap_dump.c 1.1 92/06/11 22:53:15";
#endif

#include <stdio.h>
#include <sys/types.h>
#ifdef SYSV40
#include <netinet/in.h>
#include <rpc/rpcent.h>
#else
#include <netdb.h>
#endif
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpc/pmap_prot.h>

static char *protoname();

#ifndef INADDR_LOOPBACK
#define INADDR_LOOPBACK ntohl(inet_addr("127.0.0.1"))
#endif

static void    get_myloopaddress(addrp)
struct sockaddr_in *addrp;
{
    memset((char *) addrp, 0, sizeof(*addrp));
    addrp->sin_family = AF_INET;
    addrp->sin_port = htons(PMAPPORT);
    addrp->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
}

int
main(argc, argv)
int     argc;
char  **argv;
{
    struct sockaddr_in addr;
    register struct pmaplist *list;
    register struct rpcent *rpc;

    get_myloopaddress(&addr);

    for (list = pmap_getmaps(&addr); list; list = list->pml_next) {
	rpc = getrpcbynumber((int) list->pml_map.pm_prog);
	printf("%10lu %4lu %5s %6lu  %s\n",
	       list->pml_map.pm_prog,
	       list->pml_map.pm_vers,
	       protoname(list->pml_map.pm_prot),
	       list->pml_map.pm_port,
	       rpc ? rpc->r_name : "");
    }
#undef perror
    return (fclose(stdout) ? (perror(argv[0]), 1) : 0);
}

static char *protoname(proto)
u_long  proto;
{
    static char buf[BUFSIZ];

    switch (proto) {
    case IPPROTO_UDP:
	return ("udp");
    case IPPROTO_TCP:
	return ("tcp");
    default:
	sprintf(buf, "%lu", proto);
	return (buf);
    }
}