]> The Tcpdump Group git mirrors - tcpdump/blob - print-sunrpc.c
s/sprintf/snprintf/.
[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.30 2000-01-17 06:24:26 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
47 #include <rpc/rpc.h>
48 #ifdef HAVE_RPC_RPCENT_H
49 #include <rpc/rpcent.h>
50 #endif
51 #include <rpc/pmap_prot.h>
52
53 #include <ctype.h>
54 #include <netdb.h>
55 #include <stdio.h>
56 #include <string.h>
57
58 #include "interface.h"
59 #include "addrtoname.h"
60
61 static struct tok proc2str[] = {
62 { PMAPPROC_NULL, "null" },
63 { PMAPPROC_SET, "set" },
64 { PMAPPROC_UNSET, "unset" },
65 { PMAPPROC_GETPORT, "getport" },
66 { PMAPPROC_DUMP, "dump" },
67 { PMAPPROC_CALLIT, "call" },
68 { 0, NULL }
69 };
70
71 /* Forwards */
72 static char *progstr(u_int32_t);
73
74 void
75 sunrpcrequest_print(register const u_char *bp, register u_int length,
76 register const u_char *bp2)
77 {
78 register const struct rpc_msg *rp;
79 register const struct ip *ip;
80 u_int32_t x;
81
82 rp = (struct rpc_msg *)bp;
83 ip = (struct ip *)bp2;
84
85 if (!nflag)
86 (void)printf("%s.%x > %s.sunrpc: %d",
87 ipaddr_string(&ip->ip_src),
88 (u_int32_t)ntohl(rp->rm_xid),
89 ipaddr_string(&ip->ip_dst),
90 length);
91 else
92 (void)printf("%s.%x > %s.%x: %d",
93 ipaddr_string(&ip->ip_src),
94 (u_int32_t)ntohl(rp->rm_xid),
95 ipaddr_string(&ip->ip_dst),
96 PMAPPORT,
97 length);
98 printf(" %s", tok2str(proc2str, " proc #%u",
99 (u_int32_t)ntohl(rp->rm_call.cb_proc)));
100 x = ntohl(rp->rm_call.cb_rpcvers);
101 if (x != 2)
102 printf(" [rpcver %u]", x);
103
104 switch (ntohl(rp->rm_call.cb_proc)) {
105
106 case PMAPPROC_SET:
107 case PMAPPROC_UNSET:
108 case PMAPPROC_GETPORT:
109 case PMAPPROC_CALLIT:
110 x = ntohl(rp->rm_call.cb_prog);
111 if (!nflag)
112 printf(" %s", progstr(x));
113 else
114 printf(" %u", x);
115 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers));
116 break;
117 }
118 }
119
120 static char *
121 progstr(prog)
122 u_int32_t prog;
123 {
124 register struct rpcent *rp;
125 static char buf[32];
126 static int lastprog = 0;
127
128 if (lastprog != 0 && prog == lastprog)
129 return (buf);
130 rp = getrpcbynumber(prog);
131 if (rp == NULL)
132 (void) snprintf(buf, sizeof(buf), "#%u", prog);
133 else
134 strcpy(buf, rp->r_name);
135 return (buf);
136 }