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