home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / tcpdumpb.zip / print-sunrpc.c < prev    next >
C/C++ Source or Header  |  1997-02-25  |  4KB  |  136 lines

  1. /*
  2.  * Copyright (c) 1992, 1993, 1994, 1995, 1996
  3.  *      The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] =
  24.     "@(#) $Header: print-sunrpc.c,v 1.24 96/07/23 14:17:27 leres Exp $ (LBL)";
  25. #endif
  26.  
  27. #include <sys/param.h>
  28. #include <sys/time.h>
  29. #include <sys/socket.h>
  30.  
  31. #if __STDC__
  32. struct mbuf;
  33. struct rtentry;
  34. #endif
  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. #ifndef __EMX__
  42. #include <netinet/ip_var.h>
  43. #endif
  44.  
  45. #include <rpc/rpc.h>
  46. #ifdef HAVE_RPC_RPCENT_H
  47. #include <rpc/rpcent.h>
  48. #endif
  49. #include <rpc/pmap_prot.h>
  50.  
  51. #include <ctype.h>
  52. #include <netdb.h>
  53. #include <stdio.h>
  54. #include <string.h>
  55.  
  56. #include "interface.h"
  57. #include "addrtoname.h"
  58.  
  59. static struct tok proc2str[] = {
  60.         { PMAPPROC_NULL,        "null" },
  61.         { PMAPPROC_SET,         "set" },
  62.         { PMAPPROC_UNSET,       "unset" },
  63.         { PMAPPROC_GETPORT,     "getport" },
  64.         { PMAPPROC_DUMP,        "dump" },
  65.         { PMAPPROC_CALLIT,      "call" },
  66.         { 0,                    NULL }
  67. };
  68.  
  69. /* Forwards */
  70. static char *progstr(u_int32_t);
  71.  
  72. void
  73. sunrpcrequest_print(register const u_char *bp, register u_int length,
  74.                     register const u_char *bp2)
  75. {
  76.         register const struct rpc_msg *rp;
  77.         register const struct ip *ip;
  78.         u_int32_t x;
  79.  
  80.         rp = (struct rpc_msg *)bp;
  81.         ip = (struct ip *)bp2;
  82.  
  83.         if (!nflag)
  84.                 (void)printf("%s.%x > %s.sunrpc: %d",
  85.                              ipaddr_string(&ip->ip_src),
  86.                              (u_int32_t)ntohl(rp->rm_xid),
  87.                              ipaddr_string(&ip->ip_dst),
  88.                              length);
  89.         else
  90.                 (void)printf("%s.%x > %s.%x: %d",
  91.                              ipaddr_string(&ip->ip_src),
  92.                              (u_int32_t)ntohl(rp->rm_xid),
  93.                              ipaddr_string(&ip->ip_dst),
  94.                              PMAPPORT,
  95.                              length);
  96.         printf(" %s", tok2str(proc2str, " proc #%u",
  97.             (u_int32_t)ntohl(rp->rm_call.cb_proc)));
  98.         x = ntohl(rp->rm_call.cb_rpcvers);
  99.         if (x != 2)
  100.                 printf(" [rpcver %u]", x);
  101.  
  102.         switch (ntohl(rp->rm_call.cb_proc)) {
  103.  
  104.         case PMAPPROC_SET:
  105.         case PMAPPROC_UNSET:
  106.         case PMAPPROC_GETPORT:
  107.         case PMAPPROC_CALLIT:
  108.                 x = ntohl(rp->rm_call.cb_prog);
  109.                 if (!nflag)
  110.                         printf(" %s", progstr(x));
  111.                 else
  112.                         printf(" %u", x);
  113.                 printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers));
  114.                 break;
  115.         }
  116. }
  117.  
  118. static char *
  119. progstr(prog)
  120.         u_int32_t prog;
  121. {
  122.         register struct rpcent *rp;
  123.         static char buf[32];
  124.         static lastprog = 0;
  125.  
  126.         if (lastprog != 0 && prog == lastprog)
  127.                 return (buf);
  128.         rp = getrpcbynumber(prog);
  129.         if (rp == NULL)
  130.                 (void) sprintf(buf, "#%u", prog);
  131.         else
  132.                 strcpy(buf, rp->r_name);
  133.         return (buf);
  134. }
  135.  
  136.