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[] _U_ = 26 "@(#) $Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.47 2005-04-27 21:43:48 guy Exp $ (LBL)"; 27 #endif 28 29 #ifdef HAVE_CONFIG_H 30 #include "config.h" 31 #endif 32 33 #include <tcpdump-stdinc.h> 34 35 #ifdef HAVE_GETRPCBYNUMBER 36 #include <rpc/rpc.h> 37 #ifdef HAVE_RPC_RPCENT_H 38 #include <rpc/rpcent.h> 39 #endif /* HAVE_RPC_RPCENT_H */ 40 #endif /* HAVE_GETRPCBYNUMBER */ 41 42 #include <stdio.h> 43 #include <string.h> 44 45 #include "interface.h" 46 #include "addrtoname.h" 47 #include "extract.h" 48 49 #include "ip.h" 50 #ifdef INET6 51 #include "ip6.h" 52 #endif 53 54 #include "rpc_auth.h" 55 #include "rpc_msg.h" 56 #include "pmap_prot.h" 57 58 static struct tok proc2str[] = { 59 { SUNRPC_PMAPPROC_NULL, "null" }, 60 { SUNRPC_PMAPPROC_SET, "set" }, 61 { SUNRPC_PMAPPROC_UNSET, "unset" }, 62 { SUNRPC_PMAPPROC_GETPORT, "getport" }, 63 { SUNRPC_PMAPPROC_DUMP, "dump" }, 64 { SUNRPC_PMAPPROC_CALLIT, "call" }, 65 { 0, NULL } 66 }; 67 68 /* Forwards */ 69 static char *progstr(u_int32_t); 70 71 void 72 sunrpcrequest_print(register const u_char *bp, register u_int length, 73 register const u_char *bp2) 74 { 75 register const struct sunrpc_msg *rp; 76 register const struct ip *ip; 77 #ifdef INET6 78 register const struct ip6_hdr *ip6; 79 #endif 80 u_int32_t x; 81 char srcid[20], dstid[20]; /*fits 32bit*/ 82 83 rp = (struct sunrpc_msg *)bp; 84 85 if (!nflag) { 86 snprintf(srcid, sizeof(srcid), "0x%x", 87 EXTRACT_32BITS(&rp->rm_xid)); 88 strlcpy(dstid, "sunrpc", sizeof(dstid)); 89 } else { 90 snprintf(srcid, sizeof(srcid), "0x%x", 91 EXTRACT_32BITS(&rp->rm_xid)); 92 snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT); 93 } 94 95 switch (IP_V((struct ip *)bp2)) { 96 case 4: 97 ip = (struct ip *)bp2; 98 printf("%s.%s > %s.%s: %d", 99 ipaddr_string(&ip->ip_src), srcid, 100 ipaddr_string(&ip->ip_dst), dstid, length); 101 break; 102 #ifdef INET6 103 case 6: 104 ip6 = (struct ip6_hdr *)bp2; 105 printf("%s.%s > %s.%s: %d", 106 ip6addr_string(&ip6->ip6_src), srcid, 107 ip6addr_string(&ip6->ip6_dst), dstid, length); 108 break; 109 #endif 110 default: 111 printf("%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length); 112 break; 113 } 114 115 printf(" %s", tok2str(proc2str, " proc #%u", 116 EXTRACT_32BITS(&rp->rm_call.cb_proc))); 117 x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers); 118 if (x != 2) 119 printf(" [rpcver %u]", x); 120 121 switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) { 122 123 case SUNRPC_PMAPPROC_SET: 124 case SUNRPC_PMAPPROC_UNSET: 125 case SUNRPC_PMAPPROC_GETPORT: 126 case SUNRPC_PMAPPROC_CALLIT: 127 x = EXTRACT_32BITS(&rp->rm_call.cb_prog); 128 if (!nflag) 129 printf(" %s", progstr(x)); 130 else 131 printf(" %u", x); 132 printf(".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers)); 133 break; 134 } 135 } 136 137 static char * 138 progstr(prog) 139 u_int32_t prog; 140 { 141 #ifdef HAVE_GETRPCBYNUMBER 142 register struct rpcent *rp; 143 #endif 144 static char buf[32]; 145 static u_int32_t lastprog = 0; 146 147 if (lastprog != 0 && prog == lastprog) 148 return (buf); 149 #ifdef HAVE_GETRPCBYNUMBER 150 rp = getrpcbynumber(prog); 151 if (rp == NULL) 152 #endif 153 (void) snprintf(buf, sizeof(buf), "#%u", prog); 154 #ifdef HAVE_GETRPCBYNUMBER 155 else 156 strlcpy(buf, rp->r_name, sizeof(buf)); 157 #endif 158 return (buf); 159 } 160