Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / tcpdump / print-sunrpc.c
blobdd3301ce5a95225d9c8b7bc1033cc2cf72e7a7c1
1 /* $NetBSD$ */
3 /*
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code distributions
9 * retain the above copyright notice and this paragraph in its entirety, (2)
10 * distributions including binary code include the above copyright notice and
11 * this paragraph in its entirety in the documentation or other materials
12 * provided with the distribution, and (3) all advertising materials mentioning
13 * features or use of this software display the following acknowledgement:
14 * ``This product includes software developed by the University of California,
15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16 * the University nor the names of its contributors may be used to endorse
17 * or promote products derived from this software without specific prior
18 * written permission.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 #include <sys/cdefs.h>
25 #ifndef lint
26 #if 0
27 static const char rcsid[] _U_ =
28 "@(#) Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.46.2.1 2005/04/27 21:44:06 guy Exp (LBL)";
29 #else
30 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
31 #endif
32 #endif
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #include <tcpdump-stdinc.h>
40 #ifdef HAVE_GETRPCBYNUMBER
41 #include <rpc/rpc.h>
42 #ifdef HAVE_RPC_RPCENT_H
43 #include <rpc/rpcent.h>
44 #endif /* HAVE_RPC_RPCENT_H */
45 #endif /* HAVE_GETRPCBYNUMBER */
47 #include <stdio.h>
48 #include <string.h>
50 #include "interface.h"
51 #include "addrtoname.h"
52 #include "extract.h"
54 #include "ip.h"
55 #ifdef INET6
56 #include "ip6.h"
57 #endif
59 #include "rpc_auth.h"
60 #include "rpc_msg.h"
61 #include "pmap_prot.h"
63 static struct tok proc2str[] = {
64 { SUNRPC_PMAPPROC_NULL, "null" },
65 { SUNRPC_PMAPPROC_SET, "set" },
66 { SUNRPC_PMAPPROC_UNSET, "unset" },
67 { SUNRPC_PMAPPROC_GETPORT, "getport" },
68 { SUNRPC_PMAPPROC_DUMP, "dump" },
69 { SUNRPC_PMAPPROC_CALLIT, "call" },
70 { 0, NULL }
73 /* Forwards */
74 static char *progstr(u_int32_t);
76 void
77 sunrpcrequest_print(register const u_char *bp, register u_int length,
78 register const u_char *bp2)
80 register const struct sunrpc_msg *rp;
81 register const struct ip *ip;
82 #ifdef INET6
83 register const struct ip6_hdr *ip6;
84 #endif
85 u_int32_t x;
86 char srcid[20], dstid[20]; /*fits 32bit*/
88 rp = (struct sunrpc_msg *)bp;
90 if (!nflag) {
91 snprintf(srcid, sizeof(srcid), "0x%x",
92 EXTRACT_32BITS(&rp->rm_xid));
93 strlcpy(dstid, "sunrpc", sizeof(dstid));
94 } else {
95 snprintf(srcid, sizeof(srcid), "0x%x",
96 EXTRACT_32BITS(&rp->rm_xid));
97 snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT);
100 switch (IP_V((struct ip *)bp2)) {
101 case 4:
102 ip = (struct ip *)bp2;
103 printf("%s.%s > %s.%s: %d",
104 ipaddr_string(&ip->ip_src), srcid,
105 ipaddr_string(&ip->ip_dst), dstid, length);
106 break;
107 #ifdef INET6
108 case 6:
109 ip6 = (struct ip6_hdr *)bp2;
110 printf("%s.%s > %s.%s: %d",
111 ip6addr_string(&ip6->ip6_src), srcid,
112 ip6addr_string(&ip6->ip6_dst), dstid, length);
113 break;
114 #endif
115 default:
116 printf("%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length);
117 break;
120 printf(" %s", tok2str(proc2str, " proc #%u",
121 EXTRACT_32BITS(&rp->rm_call.cb_proc)));
122 x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers);
123 if (x != 2)
124 printf(" [rpcver %u]", x);
126 switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) {
128 case SUNRPC_PMAPPROC_SET:
129 case SUNRPC_PMAPPROC_UNSET:
130 case SUNRPC_PMAPPROC_GETPORT:
131 case SUNRPC_PMAPPROC_CALLIT:
132 x = EXTRACT_32BITS(&rp->rm_call.cb_prog);
133 if (!nflag)
134 printf(" %s", progstr(x));
135 else
136 printf(" %u", x);
137 printf(".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers));
138 break;
142 static char *
143 progstr(prog)
144 u_int32_t prog;
146 #ifdef HAVE_GETRPCBYNUMBER
147 register struct rpcent *rp;
148 #endif
149 static char buf[32];
150 static u_int32_t lastprog = 0;
152 if (lastprog != 0 && prog == lastprog)
153 return (buf);
154 #ifdef HAVE_GETRPCBYNUMBER
155 rp = getrpcbynumber(prog);
156 if (rp == NULL)
157 #endif
158 (void) snprintf(buf, sizeof(buf), "#%u", prog);
159 #ifdef HAVE_GETRPCBYNUMBER
160 else
161 strlcpy(buf, rp->r_name, sizeof(buf));
162 #endif
163 return (buf);