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