]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/tcpdump/print-sunrpc.c
This commit was generated by cvs2svn to compensate for changes in r99179,
[FreeBSD/FreeBSD.git] / contrib / 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  * $FreeBSD$
22  */
23
24 #ifndef lint
25 static const char rcsid[] =
26     "@(#) $Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.39 2000/10/07 05:53:13 itojun Exp $ (LBL)";
27 #endif
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <sys/param.h>
34 #include <sys/time.h>
35 #include <sys/socket.h>
36
37 struct mbuf;
38 struct rtentry;
39
40 #include <netinet/in.h>
41
42 #include <rpc/rpc.h>
43 #ifdef HAVE_RPC_RPCENT_H
44 #include <rpc/rpcent.h>
45 #endif
46 #include <rpc/pmap_prot.h>
47
48 #include <ctype.h>
49 #include <netdb.h>
50 #include <stdio.h>
51 #include <string.h>
52
53 #include "interface.h"
54 #include "addrtoname.h"
55
56 #include "ip.h"
57 #ifdef INET6
58 #include "ip6.h"
59 #endif
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 #ifdef INET6
81         register const struct ip6_hdr *ip6;
82 #endif
83         u_int32_t x;
84         char srcid[20], dstid[20];      /*fits 32bit*/
85
86         rp = (struct rpc_msg *)bp;
87
88         if (!nflag) {
89                 snprintf(srcid, sizeof(srcid), "0x%x",
90                     (u_int32_t)ntohl(rp->rm_xid));
91                 strlcpy(dstid, "sunrpc", sizeof(dstid));
92         } else {
93                 snprintf(srcid, sizeof(srcid), "0x%x",
94                     (u_int32_t)ntohl(rp->rm_xid));
95                 snprintf(dstid, sizeof(dstid), "0x%x", PMAPPORT);
96         }
97
98         switch (IP_V((struct ip *)bp2)) {
99         case 4:
100                 ip = (struct ip *)bp2;
101                 printf("%s.%s > %s.%s: %d",
102                     ipaddr_string(&ip->ip_src), srcid,
103                     ipaddr_string(&ip->ip_dst), dstid, length);
104                 break;
105 #ifdef INET6
106         case 6:
107                 ip6 = (struct ip6_hdr *)bp2;
108                 printf("%s.%s > %s.%s: %d",
109                     ip6addr_string(&ip6->ip6_src), srcid,
110                     ip6addr_string(&ip6->ip6_dst), dstid, length);
111                 break;
112 #endif
113         default:
114                 printf("%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length);
115                 break;
116         }
117
118         printf(" %s", tok2str(proc2str, " proc #%u",
119             (u_int32_t)ntohl(rp->rm_call.cb_proc)));
120         x = ntohl(rp->rm_call.cb_rpcvers);
121         if (x != 2)
122                 printf(" [rpcver %u]", x);
123
124         switch (ntohl(rp->rm_call.cb_proc)) {
125
126         case PMAPPROC_SET:
127         case PMAPPROC_UNSET:
128         case PMAPPROC_GETPORT:
129         case PMAPPROC_CALLIT:
130                 x = ntohl(rp->rm_call.cb_prog);
131                 if (!nflag)
132                         printf(" %s", progstr(x));
133                 else
134                         printf(" %u", x);
135                 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers));
136                 break;
137         }
138 }
139
140 static char *
141 progstr(prog)
142         u_int32_t prog;
143 {
144         register struct rpcent *rp;
145         static char buf[32];
146         static int lastprog = 0;
147
148         if (lastprog != 0 && prog == lastprog)
149                 return (buf);
150         rp = getrpcbynumber(prog);
151         if (rp == NULL)
152                 (void) snprintf(buf, sizeof(buf), "#%u", prog);
153         else
154                 strlcpy(buf, rp->r_name, sizeof(buf));
155         return (buf);
156 }