1 /* $OpenBSD: print-sunrpc.c,v 1.23 2023/09/06 05:54:07 jsg 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 u_int32_t x; 67 68 rp = (struct rpc_msg *)bp; 69 70 printf("xid 0x%x %d", (u_int32_t)ntohl(rp->rm_xid), length); 71 printf(" %s", tok2str(proc2str, " proc #%u", 72 (u_int32_t)ntohl(rp->rm_call.cb_proc))); 73 x = ntohl(rp->rm_call.cb_rpcvers); 74 if (x != 2) 75 printf(" [rpcver %u]", x); 76 77 switch (ntohl(rp->rm_call.cb_proc)) { 78 79 case PMAPPROC_SET: 80 case PMAPPROC_UNSET: 81 case PMAPPROC_GETPORT: 82 case PMAPPROC_CALLIT: 83 x = ntohl(rp->rm_call.cb_prog); 84 if (!nflag) 85 printf(" %s", progstr(x)); 86 else 87 printf(" %u", x); 88 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers)); 89 break; 90 } 91 } 92 93 static char * 94 progstr(u_int32_t prog) 95 { 96 char progname[32]; 97 static char buf[32]; 98 static int lastprog = 0; 99 100 if (lastprog != 0 && prog == lastprog) 101 return (buf); 102 lastprog = prog; 103 if (priv_getrpcbynumber(prog, progname, sizeof(progname)) == 0) 104 snprintf(buf, sizeof(buf), "#%u", prog); 105 else 106 strlcpy(buf, progname, sizeof(buf)); 107 return (buf); 108 } 109