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