print-sunrpc.c revision 1.19
1/*	$OpenBSD: print-sunrpc.c,v 1.19 2015/01/16 06:40:21 deraadt Exp $	*/
2
3/*
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 */
23
24#include <sys/time.h>
25#include <sys/socket.h>
26
27struct mbuf;
28struct rtentry;
29#include <net/if.h>
30
31#include <netinet/in.h>
32#include <netinet/if_ether.h>
33#include <netinet/ip.h>
34#include <netinet/ip_var.h>
35
36#include <rpc/rpc.h>
37#ifdef HAVE_RPC_RPCENT_H
38#include <rpc/rpcent.h>
39#endif
40#include <rpc/pmap_prot.h>
41
42#include <ctype.h>
43#include <netdb.h>
44#include <stdio.h>
45#include <string.h>
46
47#include "interface.h"
48#include "addrtoname.h"
49#include "privsep.h"
50
51static struct tok proc2str[] = {
52	{ PMAPPROC_NULL,	"null" },
53	{ PMAPPROC_SET,		"set" },
54	{ PMAPPROC_UNSET,	"unset" },
55	{ PMAPPROC_GETPORT,	"getport" },
56	{ PMAPPROC_DUMP,	"dump" },
57	{ PMAPPROC_CALLIT,	"call" },
58	{ 0,			NULL }
59};
60
61/* Forwards */
62static char *progstr(u_int32_t);
63
64void
65sunrpcrequest_print(register const u_char *bp, register u_int length,
66		    register const u_char *bp2)
67{
68	register const struct rpc_msg *rp;
69	register const struct ip *ip;
70	u_int32_t x;
71
72	rp = (struct rpc_msg *)bp;
73	ip = (struct ip *)bp2;
74
75	printf("xid 0x%x %d", (u_int32_t)ntohl(rp->rm_xid), length);
76	printf(" %s", tok2str(proc2str, " proc #%u",
77	    (u_int32_t)ntohl(rp->rm_call.cb_proc)));
78	x = ntohl(rp->rm_call.cb_rpcvers);
79	if (x != 2)
80		printf(" [rpcver %u]", x);
81
82	switch (ntohl(rp->rm_call.cb_proc)) {
83
84	case PMAPPROC_SET:
85	case PMAPPROC_UNSET:
86	case PMAPPROC_GETPORT:
87	case PMAPPROC_CALLIT:
88		x = ntohl(rp->rm_call.cb_prog);
89		if (!nflag)
90			printf(" %s", progstr(x));
91		else
92			printf(" %u", x);
93		printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers));
94		break;
95	}
96}
97
98static char *
99progstr(prog)
100	u_int32_t prog;
101{
102	char progname[32];
103	static char buf[32];
104	static int lastprog = 0;
105
106	if (lastprog != 0 && prog == lastprog)
107		return (buf);
108	lastprog = prog;
109        if (priv_getrpcbynumber(prog, progname, sizeof(progname)) == 0)
110		snprintf(buf, sizeof(buf), "#%u", prog);
111	else
112		strlcpy(buf, progname, sizeof(buf));
113	return (buf);
114}
115