print-sunrpc.c revision 39300
1116742Ssam/*
2116742Ssam * Copyright (c) 1992, 1993, 1994, 1995, 1996
3116742Ssam *	The Regents of the University of California.  All rights reserved.
4116742Ssam *
5116742Ssam * Redistribution and use in source and binary forms, with or without
6116742Ssam * modification, are permitted provided that: (1) source code distributions
7116742Ssam * retain the above copyright notice and this paragraph in its entirety, (2)
8116742Ssam * distributions including binary code include the above copyright notice and
9116742Ssam * this paragraph in its entirety in the documentation or other materials
10116742Ssam * provided with the distribution, and (3) all advertising materials mentioning
11116742Ssam * features or use of this software display the following acknowledgement:
12116742Ssam * ``This product includes software developed by the University of California,
13116742Ssam * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14116742Ssam * the University nor the names of its contributors may be used to endorse
15116742Ssam * or promote products derived from this software without specific prior
16116742Ssam * written permission.
17116742Ssam * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18116742Ssam * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19116742Ssam * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20116742Ssam */
21116742Ssam
22116742Ssam#ifndef lint
23116742Ssamstatic const char rcsid[] =
24116742Ssam    "@(#) $Header: print-sunrpc.c,v 1.26 96/12/31 21:27:43 leres Exp $ (LBL)";
25116742Ssam#endif
26116742Ssam
27116742Ssam#include <sys/param.h>
28116742Ssam#include <sys/time.h>
29116742Ssam#include <sys/socket.h>
30116742Ssam
31116742Ssam#if __STDC__
32116742Ssamstruct mbuf;
33116742Ssamstruct rtentry;
34116742Ssam#endif
35116742Ssam#include <net/if.h>
36116742Ssam
37116742Ssam#include <netinet/in.h>
38116742Ssam#include <net/ethernet.h>
39116742Ssam#include <netinet/in_systm.h>
40116742Ssam#include <netinet/ip.h>
41116742Ssam#include <netinet/ip_var.h>
42116742Ssam
43116742Ssam#include <rpc/rpc.h>
44116742Ssam#ifdef HAVE_RPC_RPCENT_H
45116742Ssam#include <rpc/rpcent.h>
46116742Ssam#endif
47116742Ssam#include <rpc/pmap_prot.h>
48116742Ssam
49116742Ssam#include <ctype.h>
50116742Ssam#include <netdb.h>
51116742Ssam#include <stdio.h>
52116742Ssam#include <string.h>
53116742Ssam
54116742Ssam#include "interface.h"
55116742Ssam#include "addrtoname.h"
56116742Ssam
57116742Ssamstatic struct tok proc2str[] = {
58116742Ssam	{ PMAPPROC_NULL,	"null" },
59116742Ssam	{ PMAPPROC_SET,		"set" },
60116742Ssam	{ PMAPPROC_UNSET,	"unset" },
61116742Ssam	{ PMAPPROC_GETPORT,	"getport" },
62116742Ssam	{ PMAPPROC_DUMP,	"dump" },
63116742Ssam	{ PMAPPROC_CALLIT,	"call" },
64116742Ssam	{ 0,			NULL }
65116742Ssam};
66116742Ssam
67116742Ssam/* Forwards */
68116742Ssamstatic char *progstr(u_int32_t);
69
70void
71sunrpcrequest_print(register const u_char *bp, register u_int length,
72		    register const u_char *bp2)
73{
74	register const struct rpc_msg *rp;
75	register const struct ip *ip;
76	u_int32_t x;
77
78	rp = (struct rpc_msg *)bp;
79	ip = (struct ip *)bp2;
80
81	if (!nflag)
82		(void)printf("%s.%x > %s.sunrpc: %d",
83			     ipaddr_string(&ip->ip_src),
84			     (u_int32_t)ntohl(rp->rm_xid),
85			     ipaddr_string(&ip->ip_dst),
86			     length);
87	else
88		(void)printf("%s.%x > %s.%x: %d",
89			     ipaddr_string(&ip->ip_src),
90			     (u_int32_t)ntohl(rp->rm_xid),
91			     ipaddr_string(&ip->ip_dst),
92			     PMAPPORT,
93			     length);
94	printf(" %s", tok2str(proc2str, " proc #%u",
95	    (u_int32_t)ntohl(rp->rm_call.cb_proc)));
96	x = ntohl(rp->rm_call.cb_rpcvers);
97	if (x != 2)
98		printf(" [rpcver %u]", x);
99
100	switch (ntohl(rp->rm_call.cb_proc)) {
101
102	case PMAPPROC_SET:
103	case PMAPPROC_UNSET:
104	case PMAPPROC_GETPORT:
105	case PMAPPROC_CALLIT:
106		x = ntohl(rp->rm_call.cb_prog);
107		if (!nflag)
108			printf(" %s", progstr(x));
109		else
110			printf(" %u", x);
111		printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers));
112		break;
113	}
114}
115
116static char *
117progstr(prog)
118	u_int32_t prog;
119{
120	register struct rpcent *rp;
121	static char buf[32];
122	static int lastprog = 0;
123
124	if (lastprog != 0 && prog == lastprog)
125		return (buf);
126	rp = getrpcbynumber(prog);
127	if (rp == NULL)
128		(void) sprintf(buf, "#%u", prog);
129	else
130		strcpy(buf, rp->r_name);
131	return (buf);
132}
133