]>
The Tcpdump Group git mirrors - tcpdump/blob - print-sunrpc.c
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
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
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.
22 /* \summary: Sun Remote Procedure Call printer */
29 * 1) getrpcbynumber() is declared in <netdb.h>, not any of the RPC
34 * 2) if _XOPEN_SOURCE_EXTENDED is defined, <netdb.h> doesn't declare
39 #undef _XOPEN_SOURCE_EXTENDED
41 #include "netdissect-stdinc.h"
43 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_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) */
53 #define ND_LONGJMP_FROM_TCHECK
54 #include "netdissect.h"
55 #include "addrtoname.h"
65 * Copyright (c) 2009, Sun Microsystems, Inc.
66 * All rights reserved.
68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that the following conditions are met:
70 * - Redistributions of source code must retain the above copyright notice,
71 * this list of conditions and the following disclaimer.
72 * - Redistributions in binary form must reproduce the above copyright notice,
73 * this list of conditions and the following disclaimer in the documentation
74 * and/or other materials provided with the distribution.
75 * - Neither the name of Sun Microsystems, Inc. nor the names of its
76 * contributors may be used to endorse or promote products derived
77 * from this software without specific prior written permission.
79 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
80 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
83 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
84 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
85 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
86 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
87 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
89 * POSSIBILITY OF SUCH DAMAGE.
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 $
98 * Protocol for the local binder service, or pmap.
100 * Copyright (C) 1984, Sun Microsystems, Inc.
102 * The following procedures are supported by the protocol:
104 * PMAPPROC_NULL() returns ()
105 * takes nothing, returns nothing
107 * PMAPPROC_SET(struct pmap) returns (bool_t)
108 * TRUE is success, FALSE is failure. Registers the tuple
109 * [prog, vers, prot, port].
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.
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!
119 * PMAPPROC_DUMP() RETURNS (struct pmaplist *)
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.
130 * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
133 #define SUNRPC_PMAPPORT ((uint16_t)111)
134 #define SUNRPC_PMAPPROC_NULL ((uint32_t)0)
135 #define SUNRPC_PMAPPROC_SET ((uint32_t)1)
136 #define SUNRPC_PMAPPROC_UNSET ((uint32_t)2)
137 #define SUNRPC_PMAPPROC_GETPORT ((uint32_t)3)
138 #define SUNRPC_PMAPPROC_DUMP ((uint32_t)4)
139 #define SUNRPC_PMAPPROC_CALLIT ((uint32_t)5)
141 static const struct tok proc2str
[] = {
142 { SUNRPC_PMAPPROC_NULL
, "null" },
143 { SUNRPC_PMAPPROC_SET
, "set" },
144 { SUNRPC_PMAPPROC_UNSET
, "unset" },
145 { SUNRPC_PMAPPROC_GETPORT
, "getport" },
146 { SUNRPC_PMAPPROC_DUMP
, "dump" },
147 { SUNRPC_PMAPPROC_CALLIT
, "call" },
152 static char *progstr(uint32_t);
155 sunrpc_print(netdissect_options
*ndo
, const u_char
*bp
,
156 u_int length
, const u_char
*bp2
)
158 const struct sunrpc_msg
*rp
;
160 const struct ip6_hdr
*ip6
;
162 char srcid
[20], dstid
[20]; /*fits 32bit*/
164 ndo
->ndo_protocol
= "sunrpc";
165 rp
= (const struct sunrpc_msg
*)bp
;
168 if (!ndo
->ndo_nflag
) {
169 snprintf(srcid
, sizeof(srcid
), "0x%x",
170 GET_BE_U_4(rp
->rm_xid
));
171 strlcpy(dstid
, "sunrpc", sizeof(dstid
));
173 snprintf(srcid
, sizeof(srcid
), "0x%x",
174 GET_BE_U_4(rp
->rm_xid
));
175 snprintf(dstid
, sizeof(dstid
), "0x%x", SUNRPC_PMAPPORT
);
178 switch (IP_V((const struct ip
*)bp2
)) {
180 ip
= (const struct ip
*)bp2
;
181 ND_PRINT("%s.%s > %s.%s: %u",
182 GET_IPADDR_STRING(ip
->ip_src
), srcid
,
183 GET_IPADDR_STRING(ip
->ip_dst
), dstid
, length
);
186 ip6
= (const struct ip6_hdr
*)bp2
;
187 ND_PRINT("%s.%s > %s.%s: %u",
188 GET_IP6ADDR_STRING(ip6
->ip6_src
), srcid
,
189 GET_IP6ADDR_STRING(ip6
->ip6_dst
), dstid
, length
);
192 ND_PRINT("%s.%s > %s.%s: %u", "?", srcid
, "?", dstid
, length
);
196 ND_PRINT(" %s", tok2str(proc2str
, " proc #%u",
197 GET_BE_U_4(rp
->rm_call
.cb_proc
)));
198 x
= GET_BE_U_4(rp
->rm_call
.cb_rpcvers
);
199 if (x
!= SUNRPC_MSG_VERSION
)
200 ND_PRINT(" [rpcver %u]", x
);
202 switch (GET_BE_U_4(rp
->rm_call
.cb_proc
)) {
204 case SUNRPC_PMAPPROC_SET
:
205 case SUNRPC_PMAPPROC_UNSET
:
206 case SUNRPC_PMAPPROC_GETPORT
:
207 case SUNRPC_PMAPPROC_CALLIT
:
208 x
= GET_BE_U_4(rp
->rm_call
.cb_prog
);
210 ND_PRINT(" %s", progstr(x
));
213 ND_PRINT(".%u", GET_BE_U_4(rp
->rm_call
.cb_vers
));
219 progstr(uint32_t prog
)
221 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
225 static uint32_t lastprog
= 0;
227 if (lastprog
!= 0 && prog
== lastprog
)
229 #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
230 rp
= getrpcbynumber(prog
);
232 strlcpy(buf
, rp
->r_name
, sizeof(buf
));
235 (void) snprintf(buf
, sizeof(buf
), "#%u", prog
);