141c99275SPeter Avalos /*
241c99275SPeter Avalos * Copyright (c) 1992, 1993, 1994, 1995, 1996
341c99275SPeter Avalos * The Regents of the University of California. All rights reserved.
441c99275SPeter Avalos *
541c99275SPeter Avalos * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos * or promote products derived from this software without specific prior
1641c99275SPeter Avalos * written permission.
1741c99275SPeter Avalos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos */
2141c99275SPeter Avalos
22411677aeSAaron LI /* \summary: Sun Remote Procedure Call printer */
2341c99275SPeter Avalos
2441c99275SPeter Avalos #ifdef HAVE_CONFIG_H
25*ed775ee7SAntonio Huete Jimenez #include <config.h>
2641c99275SPeter Avalos #endif
2741c99275SPeter Avalos
2827bfbee1SPeter Avalos /*
2927bfbee1SPeter Avalos * At least on HP-UX:
3027bfbee1SPeter Avalos *
3127bfbee1SPeter Avalos * 1) getrpcbynumber() is declared in <netdb.h>, not any of the RPC
3227bfbee1SPeter Avalos * header files
3327bfbee1SPeter Avalos *
3427bfbee1SPeter Avalos * and
3527bfbee1SPeter Avalos *
3627bfbee1SPeter Avalos * 2) if _XOPEN_SOURCE_EXTENDED is defined, <netdb.h> doesn't declare
3727bfbee1SPeter Avalos * it
3827bfbee1SPeter Avalos *
3927bfbee1SPeter Avalos * so we undefine it.
4027bfbee1SPeter Avalos */
4127bfbee1SPeter Avalos #undef _XOPEN_SOURCE_EXTENDED
4227bfbee1SPeter Avalos
43*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
4441c99275SPeter Avalos
4527bfbee1SPeter Avalos #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
4641c99275SPeter Avalos #include <rpc/rpc.h>
4741c99275SPeter Avalos #ifdef HAVE_RPC_RPCENT_H
4841c99275SPeter Avalos #include <rpc/rpcent.h>
4941c99275SPeter Avalos #endif /* HAVE_RPC_RPCENT_H */
5027bfbee1SPeter Avalos #endif /* defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) */
5141c99275SPeter Avalos
5241c99275SPeter Avalos #include <stdio.h>
5341c99275SPeter Avalos #include <string.h>
5441c99275SPeter Avalos
55*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
56411677aeSAaron LI #include "netdissect.h"
5741c99275SPeter Avalos #include "addrtoname.h"
5841c99275SPeter Avalos #include "extract.h"
5941c99275SPeter Avalos
6041c99275SPeter Avalos #include "ip.h"
6141c99275SPeter Avalos #include "ip6.h"
6241c99275SPeter Avalos
6341c99275SPeter Avalos #include "rpc_auth.h"
6441c99275SPeter Avalos #include "rpc_msg.h"
6541c99275SPeter Avalos
66411677aeSAaron LI /*
67411677aeSAaron LI * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
68411677aeSAaron LI * unrestricted use provided that this legend is included on all tape
69411677aeSAaron LI * media and as a part of the software program in whole or part. Users
70411677aeSAaron LI * may copy or modify Sun RPC without charge, but are not authorized
71411677aeSAaron LI * to license or distribute it to anyone else except as part of a product or
72411677aeSAaron LI * program developed by the user.
73411677aeSAaron LI *
74411677aeSAaron LI * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
75411677aeSAaron LI * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
76411677aeSAaron LI * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
77411677aeSAaron LI *
78411677aeSAaron LI * Sun RPC is provided with no support and without any obligation on the
79411677aeSAaron LI * part of Sun Microsystems, Inc. to assist in its use, correction,
80411677aeSAaron LI * modification or enhancement.
81411677aeSAaron LI *
82411677aeSAaron LI * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
83411677aeSAaron LI * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
84411677aeSAaron LI * OR ANY PART THEREOF.
85411677aeSAaron LI *
86411677aeSAaron LI * In no event will Sun Microsystems, Inc. be liable for any lost revenue
87411677aeSAaron LI * or profits or other special, indirect and consequential damages, even if
88411677aeSAaron LI * Sun has been advised of the possibility of such damages.
89411677aeSAaron LI *
90411677aeSAaron LI * Sun Microsystems, Inc.
91411677aeSAaron LI * 2550 Garcia Avenue
92411677aeSAaron LI * Mountain View, California 94043
93411677aeSAaron LI *
94411677aeSAaron LI * from: @(#)pmap_prot.h 1.14 88/02/08 SMI
95411677aeSAaron LI * from: @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC
96411677aeSAaron LI * $FreeBSD: src/include/rpc/pmap_prot.h,v 1.9.2.1 1999/08/29 14:39:05 peter Exp $
97411677aeSAaron LI */
98411677aeSAaron LI
99411677aeSAaron LI /*
100411677aeSAaron LI * pmap_prot.h
101411677aeSAaron LI * Protocol for the local binder service, or pmap.
102411677aeSAaron LI *
103411677aeSAaron LI * Copyright (C) 1984, Sun Microsystems, Inc.
104411677aeSAaron LI *
105411677aeSAaron LI * The following procedures are supported by the protocol:
106411677aeSAaron LI *
107411677aeSAaron LI * PMAPPROC_NULL() returns ()
108411677aeSAaron LI * takes nothing, returns nothing
109411677aeSAaron LI *
110411677aeSAaron LI * PMAPPROC_SET(struct pmap) returns (bool_t)
111411677aeSAaron LI * TRUE is success, FALSE is failure. Registers the tuple
112411677aeSAaron LI * [prog, vers, prot, port].
113411677aeSAaron LI *
114411677aeSAaron LI * PMAPPROC_UNSET(struct pmap) returns (bool_t)
115411677aeSAaron LI * TRUE is success, FALSE is failure. Un-registers pair
116411677aeSAaron LI * [prog, vers]. prot and port are ignored.
117411677aeSAaron LI *
118411677aeSAaron LI * PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
119411677aeSAaron LI * 0 is failure. Otherwise returns the port number where the pair
120411677aeSAaron LI * [prog, vers] is registered. It may lie!
121411677aeSAaron LI *
122411677aeSAaron LI * PMAPPROC_DUMP() RETURNS (struct pmaplist *)
123411677aeSAaron LI *
124411677aeSAaron LI * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
125411677aeSAaron LI * RETURNS (port, string<>);
126411677aeSAaron LI * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs);
127411677aeSAaron LI * Calls the procedure on the local machine. If it is not registered,
128411677aeSAaron LI * this procedure is quite; ie it does not return error information!!!
129411677aeSAaron LI * This procedure only is supported on rpc/udp and calls via
130411677aeSAaron LI * rpc/udp. This routine only passes null authentication parameters.
131411677aeSAaron LI * This file has no interface to xdr routines for PMAPPROC_CALLIT.
132411677aeSAaron LI *
133411677aeSAaron LI * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
134411677aeSAaron LI */
135411677aeSAaron LI
136411677aeSAaron LI #define SUNRPC_PMAPPORT ((uint16_t)111)
137411677aeSAaron LI #define SUNRPC_PMAPPROC_NULL ((uint32_t)0)
138411677aeSAaron LI #define SUNRPC_PMAPPROC_SET ((uint32_t)1)
139411677aeSAaron LI #define SUNRPC_PMAPPROC_UNSET ((uint32_t)2)
140411677aeSAaron LI #define SUNRPC_PMAPPROC_GETPORT ((uint32_t)3)
141411677aeSAaron LI #define SUNRPC_PMAPPROC_DUMP ((uint32_t)4)
142411677aeSAaron LI #define SUNRPC_PMAPPROC_CALLIT ((uint32_t)5)
143411677aeSAaron LI
144411677aeSAaron LI static const struct tok proc2str[] = {
14541c99275SPeter Avalos { SUNRPC_PMAPPROC_NULL, "null" },
14641c99275SPeter Avalos { SUNRPC_PMAPPROC_SET, "set" },
14741c99275SPeter Avalos { SUNRPC_PMAPPROC_UNSET, "unset" },
14841c99275SPeter Avalos { SUNRPC_PMAPPROC_GETPORT, "getport" },
14941c99275SPeter Avalos { SUNRPC_PMAPPROC_DUMP, "dump" },
15041c99275SPeter Avalos { SUNRPC_PMAPPROC_CALLIT, "call" },
15141c99275SPeter Avalos { 0, NULL }
15241c99275SPeter Avalos };
15341c99275SPeter Avalos
15441c99275SPeter Avalos /* Forwards */
155411677aeSAaron LI static char *progstr(uint32_t);
15641c99275SPeter Avalos
15741c99275SPeter Avalos void
sunrpc_print(netdissect_options * ndo,const u_char * bp,u_int length,const u_char * bp2)158*ed775ee7SAntonio Huete Jimenez sunrpc_print(netdissect_options *ndo, const u_char *bp,
159*ed775ee7SAntonio Huete Jimenez u_int length, const u_char *bp2)
16041c99275SPeter Avalos {
161*ed775ee7SAntonio Huete Jimenez const struct sunrpc_msg *rp;
162*ed775ee7SAntonio Huete Jimenez const struct ip *ip;
163*ed775ee7SAntonio Huete Jimenez const struct ip6_hdr *ip6;
164411677aeSAaron LI uint32_t x;
16541c99275SPeter Avalos char srcid[20], dstid[20]; /*fits 32bit*/
16641c99275SPeter Avalos
167*ed775ee7SAntonio Huete Jimenez ndo->ndo_protocol = "sunrpc";
168411677aeSAaron LI rp = (const struct sunrpc_msg *)bp;
169*ed775ee7SAntonio Huete Jimenez ND_TCHECK_SIZE(rp);
17041c99275SPeter Avalos
171411677aeSAaron LI if (!ndo->ndo_nflag) {
17241c99275SPeter Avalos snprintf(srcid, sizeof(srcid), "0x%x",
173*ed775ee7SAntonio Huete Jimenez GET_BE_U_4(rp->rm_xid));
17441c99275SPeter Avalos strlcpy(dstid, "sunrpc", sizeof(dstid));
17541c99275SPeter Avalos } else {
17641c99275SPeter Avalos snprintf(srcid, sizeof(srcid), "0x%x",
177*ed775ee7SAntonio Huete Jimenez GET_BE_U_4(rp->rm_xid));
17841c99275SPeter Avalos snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT);
17941c99275SPeter Avalos }
18041c99275SPeter Avalos
181411677aeSAaron LI switch (IP_V((const struct ip *)bp2)) {
18241c99275SPeter Avalos case 4:
183411677aeSAaron LI ip = (const struct ip *)bp2;
184*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s.%s > %s.%s: %u",
185*ed775ee7SAntonio Huete Jimenez GET_IPADDR_STRING(ip->ip_src), srcid,
186*ed775ee7SAntonio Huete Jimenez GET_IPADDR_STRING(ip->ip_dst), dstid, length);
18741c99275SPeter Avalos break;
18841c99275SPeter Avalos case 6:
189411677aeSAaron LI ip6 = (const struct ip6_hdr *)bp2;
190*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s.%s > %s.%s: %u",
191*ed775ee7SAntonio Huete Jimenez GET_IP6ADDR_STRING(ip6->ip6_src), srcid,
192*ed775ee7SAntonio Huete Jimenez GET_IP6ADDR_STRING(ip6->ip6_dst), dstid, length);
19341c99275SPeter Avalos break;
19441c99275SPeter Avalos default:
195*ed775ee7SAntonio Huete Jimenez ND_PRINT("%s.%s > %s.%s: %u", "?", srcid, "?", dstid, length);
19641c99275SPeter Avalos break;
19741c99275SPeter Avalos }
19841c99275SPeter Avalos
199*ed775ee7SAntonio Huete Jimenez ND_PRINT(" %s", tok2str(proc2str, " proc #%u",
200*ed775ee7SAntonio Huete Jimenez GET_BE_U_4(rp->rm_call.cb_proc)));
201*ed775ee7SAntonio Huete Jimenez x = GET_BE_U_4(rp->rm_call.cb_rpcvers);
202*ed775ee7SAntonio Huete Jimenez if (x != SUNRPC_MSG_VERSION)
203*ed775ee7SAntonio Huete Jimenez ND_PRINT(" [rpcver %u]", x);
20441c99275SPeter Avalos
205*ed775ee7SAntonio Huete Jimenez switch (GET_BE_U_4(rp->rm_call.cb_proc)) {
20641c99275SPeter Avalos
20741c99275SPeter Avalos case SUNRPC_PMAPPROC_SET:
20841c99275SPeter Avalos case SUNRPC_PMAPPROC_UNSET:
20941c99275SPeter Avalos case SUNRPC_PMAPPROC_GETPORT:
21041c99275SPeter Avalos case SUNRPC_PMAPPROC_CALLIT:
211*ed775ee7SAntonio Huete Jimenez x = GET_BE_U_4(rp->rm_call.cb_prog);
212411677aeSAaron LI if (!ndo->ndo_nflag)
213*ed775ee7SAntonio Huete Jimenez ND_PRINT(" %s", progstr(x));
21441c99275SPeter Avalos else
215*ed775ee7SAntonio Huete Jimenez ND_PRINT(" %u", x);
216*ed775ee7SAntonio Huete Jimenez ND_PRINT(".%u", GET_BE_U_4(rp->rm_call.cb_vers));
21741c99275SPeter Avalos break;
21841c99275SPeter Avalos }
21941c99275SPeter Avalos }
22041c99275SPeter Avalos
22141c99275SPeter Avalos static char *
progstr(uint32_t prog)222411677aeSAaron LI progstr(uint32_t prog)
22341c99275SPeter Avalos {
22427bfbee1SPeter Avalos #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
225*ed775ee7SAntonio Huete Jimenez struct rpcent *rp;
22641c99275SPeter Avalos #endif
22741c99275SPeter Avalos static char buf[32];
228411677aeSAaron LI static uint32_t lastprog = 0;
22941c99275SPeter Avalos
23041c99275SPeter Avalos if (lastprog != 0 && prog == lastprog)
23141c99275SPeter Avalos return (buf);
23227bfbee1SPeter Avalos #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
23341c99275SPeter Avalos rp = getrpcbynumber(prog);
234*ed775ee7SAntonio Huete Jimenez if (rp != NULL)
235*ed775ee7SAntonio Huete Jimenez strlcpy(buf, rp->r_name, sizeof(buf));
236*ed775ee7SAntonio Huete Jimenez else
23741c99275SPeter Avalos #endif
23841c99275SPeter Avalos (void) snprintf(buf, sizeof(buf), "#%u", prog);
239*ed775ee7SAntonio Huete Jimenez lastprog = prog;
24041c99275SPeter Avalos return (buf);
24141c99275SPeter Avalos }
242