]> The Tcpdump Group git mirrors - tcpdump/blob - print-sunrpc.c
updated version
[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 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 /*
27 * At least on HP-UX:
28 *
29 * 1) getrpcbynumber() is declared in <netdb.h>, not any of the RPC
30 * header files
31 *
32 * and
33 *
34 * 2) if _XOPEN_SOURCE_EXTENDED is defined, <netdb.h> doesn't declare
35 * it
36 *
37 * so we undefine it.
38 */
39 #undef _XOPEN_SOURCE_EXTENDED
40
41 #include <netdissect-stdinc.h>
42
43 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
44 #include <rpc/rpc.h>
45 #ifdef HAVE_RPC_RPCENT_H
46 #include <rpc/rpcent.h>
47 #endif /* HAVE_RPC_RPCENT_H */
48 #endif /* defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) */
49
50 #include <stdio.h>
51 #include <string.h>
52
53 #include "netdissect.h"
54 #include "addrtoname.h"
55 #include "extract.h"
56
57 #include "ip.h"
58 #include "ip6.h"
59
60 #include "rpc_auth.h"
61 #include "rpc_msg.h"
62
63 /*
64 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
65 * unrestricted use provided that this legend is included on all tape
66 * media and as a part of the software program in whole or part. Users
67 * may copy or modify Sun RPC without charge, but are not authorized
68 * to license or distribute it to anyone else except as part of a product or
69 * program developed by the user.
70 *
71 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
72 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
73 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
74 *
75 * Sun RPC is provided with no support and without any obligation on the
76 * part of Sun Microsystems, Inc. to assist in its use, correction,
77 * modification or enhancement.
78 *
79 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
80 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
81 * OR ANY PART THEREOF.
82 *
83 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
84 * or profits or other special, indirect and consequential damages, even if
85 * Sun has been advised of the possibility of such damages.
86 *
87 * Sun Microsystems, Inc.
88 * 2550 Garcia Avenue
89 * Mountain View, California 94043
90 *
91 * from: @(#)pmap_prot.h 1.14 88/02/08 SMI
92 * from: @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC
93 * $FreeBSD: src/include/rpc/pmap_prot.h,v 1.9.2.1 1999/08/29 14:39:05 peter Exp $
94 */
95
96 /*
97 * pmap_prot.h
98 * Protocol for the local binder service, or pmap.
99 *
100 * Copyright (C) 1984, Sun Microsystems, Inc.
101 *
102 * The following procedures are supported by the protocol:
103 *
104 * PMAPPROC_NULL() returns ()
105 * takes nothing, returns nothing
106 *
107 * PMAPPROC_SET(struct pmap) returns (bool_t)
108 * TRUE is success, FALSE is failure. Registers the tuple
109 * [prog, vers, prot, port].
110 *
111 * PMAPPROC_UNSET(struct pmap) returns (bool_t)
112 * TRUE is success, FALSE is failure. Un-registers pair
113 * [prog, vers]. prot and port are ignored.
114 *
115 * PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
116 * 0 is failure. Otherwise returns the port number where the pair
117 * [prog, vers] is registered. It may lie!
118 *
119 * PMAPPROC_DUMP() RETURNS (struct pmaplist *)
120 *
121 * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
122 * RETURNS (port, string<>);
123 * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs);
124 * Calls the procedure on the local machine. If it is not registered,
125 * this procedure is quite; ie it does not return error information!!!
126 * This procedure only is supported on rpc/udp and calls via
127 * rpc/udp. This routine only passes null authentication parameters.
128 * This file has no interface to xdr routines for PMAPPROC_CALLIT.
129 *
130 * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
131 */
132
133 #define SUNRPC_PMAPPORT ((uint16_t)111)
134 #define SUNRPC_PMAPPROG ((uint32_t)100000)
135 #define SUNRPC_PMAPVERS ((uint32_t)2)
136 #define SUNRPC_PMAPVERS_PROTO ((uint32_t)2)
137 #define SUNRPC_PMAPVERS_ORIG ((uint32_t)1)
138 #define SUNRPC_PMAPPROC_NULL ((uint32_t)0)
139 #define SUNRPC_PMAPPROC_SET ((uint32_t)1)
140 #define SUNRPC_PMAPPROC_UNSET ((uint32_t)2)
141 #define SUNRPC_PMAPPROC_GETPORT ((uint32_t)3)
142 #define SUNRPC_PMAPPROC_DUMP ((uint32_t)4)
143 #define SUNRPC_PMAPPROC_CALLIT ((uint32_t)5)
144
145 struct sunrpc_pmap {
146 uint32_t pm_prog;
147 uint32_t pm_vers;
148 uint32_t pm_prot;
149 uint32_t pm_port;
150 };
151
152 static const struct tok proc2str[] = {
153 { SUNRPC_PMAPPROC_NULL, "null" },
154 { SUNRPC_PMAPPROC_SET, "set" },
155 { SUNRPC_PMAPPROC_UNSET, "unset" },
156 { SUNRPC_PMAPPROC_GETPORT, "getport" },
157 { SUNRPC_PMAPPROC_DUMP, "dump" },
158 { SUNRPC_PMAPPROC_CALLIT, "call" },
159 { 0, NULL }
160 };
161
162 /* Forwards */
163 static char *progstr(uint32_t);
164
165 void
166 sunrpcrequest_print(netdissect_options *ndo, register const u_char *bp,
167 register u_int length, register const u_char *bp2)
168 {
169 register const struct sunrpc_msg *rp;
170 register const struct ip *ip;
171 register const struct ip6_hdr *ip6;
172 uint32_t x;
173 char srcid[20], dstid[20]; /*fits 32bit*/
174
175 rp = (const struct sunrpc_msg *)bp;
176
177 if (!ndo->ndo_nflag) {
178 snprintf(srcid, sizeof(srcid), "0x%x",
179 EXTRACT_32BITS(&rp->rm_xid));
180 strlcpy(dstid, "sunrpc", sizeof(dstid));
181 } else {
182 snprintf(srcid, sizeof(srcid), "0x%x",
183 EXTRACT_32BITS(&rp->rm_xid));
184 snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT);
185 }
186
187 switch (IP_V((const struct ip *)bp2)) {
188 case 4:
189 ip = (const struct ip *)bp2;
190 ND_PRINT((ndo, "%s.%s > %s.%s: %d",
191 ipaddr_string(ndo, &ip->ip_src), srcid,
192 ipaddr_string(ndo, &ip->ip_dst), dstid, length));
193 break;
194 case 6:
195 ip6 = (const struct ip6_hdr *)bp2;
196 ND_PRINT((ndo, "%s.%s > %s.%s: %d",
197 ip6addr_string(ndo, &ip6->ip6_src), srcid,
198 ip6addr_string(ndo, &ip6->ip6_dst), dstid, length));
199 break;
200 default:
201 ND_PRINT((ndo, "%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length));
202 break;
203 }
204
205 ND_PRINT((ndo, " %s", tok2str(proc2str, " proc #%u",
206 EXTRACT_32BITS(&rp->rm_call.cb_proc))));
207 x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers);
208 if (x != 2)
209 ND_PRINT((ndo, " [rpcver %u]", x));
210
211 switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) {
212
213 case SUNRPC_PMAPPROC_SET:
214 case SUNRPC_PMAPPROC_UNSET:
215 case SUNRPC_PMAPPROC_GETPORT:
216 case SUNRPC_PMAPPROC_CALLIT:
217 x = EXTRACT_32BITS(&rp->rm_call.cb_prog);
218 if (!ndo->ndo_nflag)
219 ND_PRINT((ndo, " %s", progstr(x)));
220 else
221 ND_PRINT((ndo, " %u", x));
222 ND_PRINT((ndo, ".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers)));
223 break;
224 }
225 }
226
227 static char *
228 progstr(uint32_t prog)
229 {
230 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
231 register struct rpcent *rp;
232 #endif
233 static char buf[32];
234 static uint32_t lastprog = 0;
235
236 if (lastprog != 0 && prog == lastprog)
237 return (buf);
238 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
239 rp = getrpcbynumber(prog);
240 if (rp == NULL)
241 #endif
242 (void) snprintf(buf, sizeof(buf), "#%u", prog);
243 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
244 else
245 strlcpy(buf, rp->r_name, sizeof(buf));
246 #endif
247 return (buf);
248 }