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