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