]> The Tcpdump Group git mirrors - tcpdump/blob - print-sunrpc.c
(token_if_print): remove unused variable
[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.33 2000-07-01 03:39:10 assar Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <sys/socket.h>
34
35 struct mbuf;
36 struct rtentry;
37 #include <net/if.h>
38
39 #include <netinet/in.h>
40 #include <netinet/if_ether.h>
41 #include <netinet/in_systm.h>
42 #include <netinet/ip.h>
43 #include <netinet/ip_var.h>
44 #ifdef INET6
45 #include <netinet/ip6.h>
46 #endif
47
48 #include <rpc/rpc.h>
49 #ifdef HAVE_RPC_RPCENT_H
50 #include <rpc/rpcent.h>
51 #endif
52 #include <rpc/pmap_prot.h>
53
54 #include <ctype.h>
55 #include <netdb.h>
56 #include <stdio.h>
57 #include <string.h>
58
59 #include "interface.h"
60 #include "addrtoname.h"
61
62 static struct tok proc2str[] = {
63 { PMAPPROC_NULL, "null" },
64 { PMAPPROC_SET, "set" },
65 { PMAPPROC_UNSET, "unset" },
66 { PMAPPROC_GETPORT, "getport" },
67 { PMAPPROC_DUMP, "dump" },
68 { PMAPPROC_CALLIT, "call" },
69 { 0, NULL }
70 };
71
72 /* Forwards */
73 static char *progstr(u_int32_t);
74
75 void
76 sunrpcrequest_print(register const u_char *bp, register u_int length,
77 register const u_char *bp2)
78 {
79 register const struct rpc_msg *rp;
80 register const struct ip *ip;
81 #ifdef INET6
82 register const struct ip6_hdr *ip6;
83 #endif
84 u_int32_t x;
85 char srcid[20], dstid[20]; /*fits 32bit*/
86
87 rp = (struct rpc_msg *)bp;
88
89 if (!nflag) {
90 snprintf(srcid, sizeof(srcid), "0x%x",
91 (u_int32_t)ntohl(rp->rm_xid));
92 strlcpy(dstid, "sunrpc", sizeof(dstid));
93 } else {
94 snprintf(srcid, sizeof(srcid), "0x%x",
95 (u_int32_t)ntohl(rp->rm_xid));
96 snprintf(dstid, sizeof(dstid), "0x%x", PMAPPORT);
97 }
98
99 switch (((struct ip *)bp2)->ip_v) {
100 case 4:
101 ip = (struct ip *)bp2;
102 printf("%s.%s > %s.%s: %d",
103 ipaddr_string(&ip->ip_src), srcid,
104 ipaddr_string(&ip->ip_dst), dstid, length);
105 break;
106 #ifdef INET6
107 case 6:
108 ip6 = (struct ip6_hdr *)bp2;
109 printf("%s.%s > %s.%s: %d",
110 ip6addr_string(&ip6->ip6_src), srcid,
111 ip6addr_string(&ip6->ip6_dst), dstid, length);
112 break;
113 #endif
114 default:
115 printf("%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length);
116 break;
117 }
118
119 printf(" %s", tok2str(proc2str, " proc #%u",
120 (u_int32_t)ntohl(rp->rm_call.cb_proc)));
121 x = ntohl(rp->rm_call.cb_rpcvers);
122 if (x != 2)
123 printf(" [rpcver %u]", x);
124
125 switch (ntohl(rp->rm_call.cb_proc)) {
126
127 case PMAPPROC_SET:
128 case PMAPPROC_UNSET:
129 case PMAPPROC_GETPORT:
130 case PMAPPROC_CALLIT:
131 x = ntohl(rp->rm_call.cb_prog);
132 if (!nflag)
133 printf(" %s", progstr(x));
134 else
135 printf(" %u", x);
136 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers));
137 break;
138 }
139 }
140
141 static char *
142 progstr(prog)
143 u_int32_t prog;
144 {
145 register struct rpcent *rp;
146 static char buf[32];
147 static int lastprog = 0;
148
149 if (lastprog != 0 && prog == lastprog)
150 return (buf);
151 rp = getrpcbynumber(prog);
152 if (rp == NULL)
153 (void) snprintf(buf, sizeof(buf), "#%u", prog);
154 else
155 strlcpy(buf, rp->r_name, sizeof(buf));
156 return (buf);
157 }