1 /* $OpenBSD: print-sunrpc.c,v 1.16 2007/10/07 16:41:05 deraadt 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 "@(#) $Id: print-sunrpc.c,v 1.16 2007/10/07 16:41:05 deraadt 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 #include "privsep.h" 57 58 static struct tok proc2str[] = { 59 { PMAPPROC_NULL, "null" }, 60 { PMAPPROC_SET, "set" }, 61 { PMAPPROC_UNSET, "unset" }, 62 { PMAPPROC_GETPORT, "getport" }, 63 { PMAPPROC_DUMP, "dump" }, 64 { 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 rpc_msg *rp; 76 register const struct ip *ip; 77 u_int32_t x; 78 79 rp = (struct rpc_msg *)bp; 80 ip = (struct ip *)bp2; 81 82 printf("xid 0x%x %d", (u_int32_t)ntohl(rp->rm_xid), length); 83 printf(" %s", tok2str(proc2str, " proc #%u", 84 (u_int32_t)ntohl(rp->rm_call.cb_proc))); 85 x = ntohl(rp->rm_call.cb_rpcvers); 86 if (x != 2) 87 printf(" [rpcver %u]", x); 88 89 switch (ntohl(rp->rm_call.cb_proc)) { 90 91 case PMAPPROC_SET: 92 case PMAPPROC_UNSET: 93 case PMAPPROC_GETPORT: 94 case PMAPPROC_CALLIT: 95 x = ntohl(rp->rm_call.cb_prog); 96 if (!nflag) 97 printf(" %s", progstr(x)); 98 else 99 printf(" %u", x); 100 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers)); 101 break; 102 } 103 } 104 105 static char * 106 progstr(prog) 107 u_int32_t prog; 108 { 109 char progname[32]; 110 static char buf[32]; 111 static int lastprog = 0; 112 113 if (lastprog != 0 && prog == lastprog) 114 return (buf); 115 lastprog = prog; 116 if (priv_getrpcbynumber(prog, progname, sizeof(progname)) == 0) 117 snprintf(buf, sizeof(buf), "#%u", prog); 118 else 119 strlcpy(buf, progname, sizeof(buf)); 120 return (buf); 121 } 122