⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _afs.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Copyright (c) 1990 The Regents of the University of California.
 * Copyright (c) 1992 Transarc Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that: (1) source code distributions
 * retain the above copyright notice and this paragraph in its entirety, (2)
 * distributions including binary code include the above copyright notice and
 * this paragraph in its entirety in the documentation or other materials
 * provided with the distribution, and (3) all advertising materials mentioning
 * features or use of this software display the following acknowledgement:
 * ``This product includes software developed by the University of California,
 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
 * the University nor the names of its contributors may be used to endorse
 * or promote products derived from this software without specific prior
 * written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#if 0
static char rcsid[] = "@(#) $Header: /afs/stacken.kth.se/src/SourceRepository/tcpdump/print-afs.c,v 1.2 1998/07/19 18:04:38 mattiasa Exp $";
#endif

#include <stdio.h>
#include <ctype.h>
#include <errno.h>

#include <sys/time.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_var.h>

#include <rpc/rpc.h>
#include <rpc/types.h>
#include <rpc/xdr.h>

#include "interfac.h"
#include "a2name.h"
#include "extract.h"
#include "afsops.h"
#include "rx.h"
#include "kasops.h"
#include "vlsops.h"
#include "volops.h"
#include "ubikops.h"
#include "rxkops.h"
#include "ptsops.h"

static char *rxtypes[RX_N_PACKET_TYPES] = RX_PACKET_TYPES;
static char *rxflags[] = RX_FLAGS;
static char *rx_ackReasons = RX_ACK_REASONS;

static char *afsopstrings[81] = {
            "FetchData      ",
            "FetchACL       ",
            "FetchStatus    ",
            "StoreData     ",
            "StoreACL      ",
            "StoreStatus   ",
            "RemoveFile    ",
            "CreateFile    ",
            "Rename                ",
            "Symlink       ",
            "Link          ",
            "MakeDir       ",
            "RemoveDir     ",
            "OldSetLock    ",
            "OldExtendLock ",
            "OldReleaseLock        ",
            "GetStatistics ",
            "GiveUpCallBacks",
            "GetVolumeInfo ",
            "GetVolumeStatus",
            "SetVolumeStatus",
            "GetRootVolume ",
            "CheckToken    ",
            "GetTime       ",
            "NGetVolumeInfo        ",
            "BulkStatus    ",
            "SetLock       ",
            "ExtendLock    ",
            "ReleaseLock   ",
            "XStatsVersion ",
            "GetXStats     ",
            "Lookup         ",
            "FlushCPS       ",
            "DFSSymlink     ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "unknown        ",
            "CallBack      ",
            "InitCallBackState",
            "Probe                 ",
            "GetLock       ",
            "GetCE                 ",
            "XStatsVersion         ",
            "GetXStats     "
          };

static char *afsports[] = {
            "fs", "cm", "pt", "vl", "ka",
            "vs", "er", "bs", "up", "rs",
            "xx", "xx", "xx", "xx", "xx",
            "xx", "xx", "xx", "xx", "xx",
            "xx", "bd"
          };

static char *rxkopstrings[RXKST_NUMBER_OPCODES] = {
            "Fast   ",
            "Slow   ",
            "Copious",
            "Kill   "
          };

static void rxack_print  (struct rx_header*, int, struct ip*, char*, char*);
static void afsreq_print (u_long *, int, struct ip *);
static void kasreq_print (u_long *, int, struct ip *);
static void ubik_print   (u_long *, int, struct ip *);
static void vlsreq_print (u_long *, int, struct ip *);
static void ptsreq_print (u_long *, int, struct ip *);
static void volreq_print (u_long *, int, struct ip *);
static void rxkreq_print (u_long *, int, struct ip *);

static __inline void printname (u_long len, char *dp)
{
  PRINTF (" %8.20s", dp);
}

static __inline void printname2 (u_long len, u_long *dp)
{
  PUTCHAR (' ');
  while (*dp)
  {
    u_long t = ntohl (*dp);
    dp++;
    PUTCHAR (t & 0xff);
  }
}

static __inline void printfid (u_long *dp)
{
  /* try to print out the FID at the beginning of this struct...
   */
  PRINTF (" %ld.%ld.%ld", ntohl(dp[0]), ntohl(dp[1]), ntohl(dp[2]));
}

static __inline void printlong (u_long *dp)
{
  PRINTF (" %ld", ntohl(dp[0]));
}

static __inline void printhost (u_long *dp)
{
  u_long ip = ntohl (dp[0]);

  PRINTF (" %d.%d.%d.%d",
          (ip >> 24) & 0xff,
          (ip >> 16) & 0xff,
          (ip >> 8) & 0xff,
          ip & 0xff);
}

void rx_print (const u_char *p, u_int length, u_int sp, u_int dp,
               u_char *bp2)
{
  struct rx_header *rp = (struct rx_header*) p;
  struct ip        *ip = (struct ip*) bp2;
  char   t[8], u[8];
  char  *sport, *dport;

  if (sp >= AFS_FSPORT && sp <= 7021)
     sport = afsports[sp - SMALLESTPORT];
  else
  {
    sprintf (t, "%x", sp);
    sport = t;
  }

  if (dp >= AFS_FSPORT && dp <= 7021)
     dport = afsports [dp - SMALLESTPORT];
  else
  {
    sprintf (u, "%x", dp);
    dport = u;
  }

  if (length < RX_HEADER_SIZE)  /* must not be truncated, I guess */
  {
    PRINTF ("%s.%s > %s.%s: truncated-RX",
            ipaddr_string (&ip->ip_src), sport,
            ipaddr_string (&ip->ip_dst), dport);
    return;
  }

  if (!nflag)
  {
    if (rp->type == RX_PACKET_TYPE_ACK)
       rxack_print (rp, length, ip, sport, dport);
    else
    {
      if (rp->flags & RX_CLIENT_INITIATED)
      {
        PRINTF ("%s.%s.%08x.%04x > %s.%s: ",
                ipaddr_string (&ip->ip_src), sport,
                ntohl (rp->cid), ntohl (rp->callNumber),
                ipaddr_string (&ip->ip_dst), dport);
        PRINTF ("%2x.%04x %s %s %3d",
                ntohl (rp->seq), ntohl (rp->serial),
                rp->type ? rxtypes[rp->type - 1] : "",
                rxflags[rp->flags], length - RX_HEADER_SIZE);

        if (rp->type == RX_PACKET_TYPE_ABORT)
           PRINTF (" %d", ntohl (*((long*)(rp+1))));

        if (ntohl (rp->seq) == 1)
        {
          if (dp == AFS_FSPORT)
             afsreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
          else if (sp == AFS_FSPORT)
          {
            if (dp == AFS_PTPORT)
                 ptsreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
            else afsreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
          }
          else if (sp == dp)
             ubik_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
          else if (dp == AFS_KAPORT || dp == AFS_VLPORT || dp == AFS_PTPORT)
          {
            u_long op = ntohl (*(u_long*)(rp + 1));

            if ((op >= UVOTE_LowestOpcode && op <= UVOTE_HighestOpcode) ||
                (op >= UDISK_LowestOpcode && op <= UDISK_HighestOpcode))
                 ubik_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
            else if (dp == AFS_KAPORT)
                 kasreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
            else if (dp == AFS_VLPORT)
                 vlsreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
            else if (dp == AFS_PTPORT)
                 ptsreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
          }
          else if (dp == AFS_VOSPORT)
               volreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
          else if (dp == RXKST_SERVICEPORT)
               rxkreq_print ((u_long*)(rp+1), length - RX_HEADER_SIZE, ip);
          else PUTCHAR ('\n');
        }
      }
      else
      {
        PRINTF ("%s.%s.%08x.%04x < %s.%s: ",
                ipaddr_string (&ip->ip_dst), dport,
                ntohl (rp->cid), ntohl (rp->callNumber),
                ipaddr_string (&ip->ip_src), sport);
        PRINTF ("%2x.%04x %s %s %3d",
                ntohl (rp->seq), ntohl (rp->serial),
                rp->type ? rxtypes[rp->type - 1] : "",
                rxflags[rp->flags], length - RX_HEADER_SIZE);

        if (rp->type == RX_PACKET_TYPE_ABORT)
           PRINTF (" %ld", ntohl(*((long*)(rp+1))));
      }
    }
  }
}

static void rxack_print (struct rx_header *rp, int len, struct ip *ip,
                         char *sport, char *dport)
{
  struct rx_ackPacket *ap;

  if (rp->flags & RX_CLIENT_INITIATED)
  {
    PRINTF ("%s.%s.%08x.%04x > %s.%s: ",
            ipaddr_string (&ip->ip_src),
            sport, ntohl (rp->cid), ntohl (rp->callNumber),
            ipaddr_string (&ip->ip_dst), dport);
  }
  else
  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -