print-sunrpc.c revision 1.2
1/* $OpenBSD: print-sunrpc.c,v 1.2 1996/03/04 15:59:39 mickey Exp $ */ 2/* $NetBSD: print-sunrpc.c,v 1.3 1995/03/06 19:11:32 mycroft Exp $ */ 3 4/* 5 * Copyright (c) 1992, 1993, 1994 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that: (1) source code distributions 10 * retain the above copyright notice and this paragraph in its entirety, (2) 11 * distributions including binary code include the above copyright notice and 12 * this paragraph in its entirety in the documentation or other materials 13 * provided with the distribution, and (3) all advertising materials mentioning 14 * features or use of this software display the following acknowledgement: 15 * ``This product includes software developed by the University of California, 16 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 17 * the University nor the names of its contributors may be used to endorse 18 * or promote products derived from this software without specific prior 19 * written permission. 20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 21 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 23 */ 24 25#ifndef lint 26static char rcsid[] = 27 "@(#) Header: print-sunrpc.c,v 1.12 94/06/14 20:18:48 leres Exp (LBL)"; 28#endif 29 30#include <sys/param.h> 31#include <sys/time.h> 32#include <sys/types.h> 33#include <sys/socket.h> 34 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#ifdef SOLARIS 44#include <tiuser.h> 45#endif 46#include <rpc/rpc.h> 47#include <rpc/pmap_prot.h> 48 49#include <ctype.h> 50#include <errno.h> 51#include <stdio.h> 52 53#include "interface.h" 54#include "addrtoname.h" 55#include "extract.h" /* must come after interface.h */ 56 57#if BYTE_ORDER == LITTLE_ENDIAN 58static void bswap(u_int32 *, u_int); 59#endif 60 61#if BYTE_ORDER == LITTLE_ENDIAN 62/* 63 * Byte swap an array of n 32-bit words. 64 * Assume input is word-aligned. 65 * Check that buffer is bounded by "snapend". 66 */ 67static void 68bswap(register u_int32 *bp, register u_int n) 69{ 70 register int nwords = ((char *)snapend - (char *)bp) / sizeof(*bp); 71 72 if (nwords > n) 73 nwords = n; 74 for (; --nwords >= 0; ++bp) 75 *bp = ntohl(*bp); 76} 77#endif 78 79static struct token proc2str[] = { 80 { PMAPPROC_NULL, "null" }, 81 { PMAPPROC_SET, "set" }, 82 { PMAPPROC_UNSET, "unset" }, 83 { PMAPPROC_GETPORT, "getport" }, 84 { PMAPPROC_DUMP, "dump" }, 85 { PMAPPROC_CALLIT, "call" }, 86 { 0, NULL } 87}; 88 89void 90sunrpcrequest_print(register const u_char *bp, register int length, 91 register const u_char *bp2) 92{ 93 register const struct rpc_msg *rp; 94 register const struct ip *ip; 95 96 rp = (struct rpc_msg *)bp; 97 ip = (struct ip *)bp2; 98 99 if (!nflag) 100 (void)printf("%s.%x > %s.sunrpc: %d", 101 ipaddr_string(&ip->ip_src), 102 ntohl(rp->rm_xid), 103 ipaddr_string(&ip->ip_dst), 104 length); 105 else 106 (void)printf("%s.%x > %s.%x: %d", 107 ipaddr_string(&ip->ip_src), 108 ntohl(rp->rm_xid), 109 ipaddr_string(&ip->ip_dst), 110 PMAPPORT, 111 length); 112 printf(" %s", tok2str(proc2str, " proc #%d", 113 ntohl(rp->rm_call.cb_proc))); 114} 115 116