1 /* $OpenBSD: print-sunrpc.c,v 1.10 2000/12/05 08:17:45 jakob 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.10 2000/12/05 08:17:45 jakob Exp $ (LBL)"; 27 #endif 28 29 #include <sys/param.h> 30 #include <sys/time.h> 31 #include <sys/socket.h> 32 33 #ifdef __STDC__ 34 struct mbuf; 35 struct rtentry; 36 #endif 37 #include <net/if.h> 38 39 #include <netinet/in.h> 40 #include <netinet/if_ether.h> 41 #include <netinet/in_systm.h> 42 #include <netinet/ip.h> 43 #include <netinet/ip_var.h> 44 45 #include <rpc/rpc.h> 46 #ifdef HAVE_RPC_RPCENT_H 47 #include <rpc/rpcent.h> 48 #endif 49 #include <rpc/pmap_prot.h> 50 51 #include <ctype.h> 52 #include <netdb.h> 53 #include <stdio.h> 54 #include <string.h> 55 56 #include "interface.h" 57 #include "addrtoname.h" 58 59 static struct tok proc2str[] = { 60 { PMAPPROC_NULL, "null" }, 61 { PMAPPROC_SET, "set" }, 62 { PMAPPROC_UNSET, "unset" }, 63 { PMAPPROC_GETPORT, "getport" }, 64 { PMAPPROC_DUMP, "dump" }, 65 { PMAPPROC_CALLIT, "call" }, 66 { 0, NULL } 67 }; 68 69 /* Forwards */ 70 static char *progstr(u_int32_t); 71 72 void 73 sunrpcrequest_print(register const u_char *bp, register u_int length, 74 register const u_char *bp2) 75 { 76 register const struct rpc_msg *rp; 77 register const struct ip *ip; 78 u_int32_t x; 79 80 rp = (struct rpc_msg *)bp; 81 ip = (struct ip *)bp2; 82 83 printf("xid 0x%x %d", (u_int32_t)ntohl(rp->rm_xid), length); 84 printf(" %s", tok2str(proc2str, " proc #%u", 85 (u_int32_t)ntohl(rp->rm_call.cb_proc))); 86 x = ntohl(rp->rm_call.cb_rpcvers); 87 if (x != 2) 88 printf(" [rpcver %u]", x); 89 90 switch (ntohl(rp->rm_call.cb_proc)) { 91 92 case PMAPPROC_SET: 93 case PMAPPROC_UNSET: 94 case PMAPPROC_GETPORT: 95 case PMAPPROC_CALLIT: 96 x = ntohl(rp->rm_call.cb_prog); 97 if (!nflag) 98 printf(" %s", progstr(x)); 99 else 100 printf(" %u", x); 101 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers)); 102 break; 103 } 104 } 105 106 static char * 107 progstr(prog) 108 u_int32_t prog; 109 { 110 register struct rpcent *rp; 111 static char buf[32]; 112 static int lastprog = 0; 113 114 if (lastprog != 0 && prog == lastprog) 115 return (buf); 116 rp = getrpcbynumber(prog); 117 if (rp == NULL) 118 (void) sprintf(buf, "#%u", prog); 119 else { 120 strncpy(buf, rp->r_name, sizeof buf-1); 121 buf[sizeof buf-1] = '\0'; 122 } 123 return (buf); 124 } 125