print-sunrpc.c revision 1.20
1/*	$OpenBSD: print-sunrpc.c,v 1.20 2015/11/16 00:16:39 mmcc 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(const u_char *bp, u_int length, const u_char *bp2)
66{
67	const struct rpc_msg *rp;
68	const struct ip *ip;
69	u_int32_t x;
70
71	rp = (struct rpc_msg *)bp;
72	ip = (struct ip *)bp2;
73
74	printf("xid 0x%x %d", (u_int32_t)ntohl(rp->rm_xid), length);
75	printf(" %s", tok2str(proc2str, " proc #%u",
76	    (u_int32_t)ntohl(rp->rm_call.cb_proc)));
77	x = ntohl(rp->rm_call.cb_rpcvers);
78	if (x != 2)
79		printf(" [rpcver %u]", x);
80
81	switch (ntohl(rp->rm_call.cb_proc)) {
82
83	case PMAPPROC_SET:
84	case PMAPPROC_UNSET:
85	case PMAPPROC_GETPORT:
86	case PMAPPROC_CALLIT:
87		x = ntohl(rp->rm_call.cb_prog);
88		if (!nflag)
89			printf(" %s", progstr(x));
90		else
91			printf(" %u", x);
92		printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers));
93		break;
94	}
95}
96
97static char *
98progstr(prog)
99	u_int32_t prog;
100{
101	char progname[32];
102	static char buf[32];
103	static int lastprog = 0;
104
105	if (lastprog != 0 && prog == lastprog)
106		return (buf);
107	lastprog = prog;
108        if (priv_getrpcbynumber(prog, progname, sizeof(progname)) == 0)
109		snprintf(buf, sizeof(buf), "#%u", prog);
110	else
111		strlcpy(buf, progname, sizeof(buf));
112	return (buf);
113}
114