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