1 /* $OpenBSD: print-sunrpc.c,v 1.13 2002/02/19 19:39:40 millert Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993, 1994, 1995, 1996 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that: (1) source code distributions 9 * retain the above copyright notice and this paragraph in its entirety, (2) 10 * distributions including binary code include the above copyright notice and 11 * this paragraph in its entirety in the documentation or other materials 12 * provided with the distribution, and (3) all advertising materials mentioning 13 * features or use of this software display the following acknowledgement: 14 * ``This product includes software developed by the University of California, 15 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 16 * the University nor the names of its contributors may be used to endorse 17 * or promote products derived from this software without specific prior 18 * written permission. 19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 20 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 22 */ 23 24 #ifndef lint 25 static const char rcsid[] = 26 "@(#) $Header: /home/cvs/src/usr.sbin/tcpdump/print-sunrpc.c,v 1.13 2002/02/19 19:39:40 millert Exp $ (LBL)"; 27 #endif 28 29 #include <sys/param.h> 30 #include <sys/time.h> 31 #include <sys/socket.h> 32 33 struct mbuf; 34 struct rtentry; 35 #include <net/if.h> 36 37 #include <netinet/in.h> 38 #include <netinet/if_ether.h> 39 #include <netinet/in_systm.h> 40 #include <netinet/ip.h> 41 #include <netinet/ip_var.h> 42 43 #include <rpc/rpc.h> 44 #ifdef HAVE_RPC_RPCENT_H 45 #include <rpc/rpcent.h> 46 #endif 47 #include <rpc/pmap_prot.h> 48 49 #include <ctype.h> 50 #include <netdb.h> 51 #include <stdio.h> 52 #include <string.h> 53 54 #include "interface.h" 55 #include "addrtoname.h" 56 57 static struct tok proc2str[] = { 58 { PMAPPROC_NULL, "null" }, 59 { PMAPPROC_SET, "set" }, 60 { PMAPPROC_UNSET, "unset" }, 61 { PMAPPROC_GETPORT, "getport" }, 62 { PMAPPROC_DUMP, "dump" }, 63 { PMAPPROC_CALLIT, "call" }, 64 { 0, NULL } 65 }; 66 67 /* Forwards */ 68 static char *progstr(u_int32_t); 69 70 void 71 sunrpcrequest_print(register const u_char *bp, register u_int length, 72 register const u_char *bp2) 73 { 74 register const struct rpc_msg *rp; 75 register const struct ip *ip; 76 u_int32_t x; 77 78 rp = (struct rpc_msg *)bp; 79 ip = (struct ip *)bp2; 80 81 printf("xid 0x%x %d", (u_int32_t)ntohl(rp->rm_xid), length); 82 printf(" %s", tok2str(proc2str, " proc #%u", 83 (u_int32_t)ntohl(rp->rm_call.cb_proc))); 84 x = ntohl(rp->rm_call.cb_rpcvers); 85 if (x != 2) 86 printf(" [rpcver %u]", x); 87 88 switch (ntohl(rp->rm_call.cb_proc)) { 89 90 case PMAPPROC_SET: 91 case PMAPPROC_UNSET: 92 case PMAPPROC_GETPORT: 93 case PMAPPROC_CALLIT: 94 x = ntohl(rp->rm_call.cb_prog); 95 if (!nflag) 96 printf(" %s", progstr(x)); 97 else 98 printf(" %u", x); 99 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers)); 100 break; 101 } 102 } 103 104 static char * 105 progstr(prog) 106 u_int32_t prog; 107 { 108 register struct rpcent *rp; 109 static char buf[32]; 110 static int lastprog = 0; 111 112 if (lastprog != 0 && prog == lastprog) 113 return (buf); 114 rp = getrpcbynumber(prog); 115 if (rp == NULL) 116 snprintf(buf, sizeof(buf), "#%u", prog); 117 else 118 strlcpy(buf, rp->r_name, sizeof(buf)); 119 return (buf); 120 } 121