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