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

📄 _rx.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
📖 第 1 页 / 共 4 页
字号:
      /* We got a match!
       */
      rx_cache_hint = i;
      *opcode = rxent->opcode;
      return (1);
    }
    if (++i > RX_CACHE_SIZE)
       i = 0;
  }
  while (i != rx_cache_hint);

  /* Our search failed
   */
  return (0);
}

/*
 * These extrememly grody macros handle the printing of various AFS stuff.
 */
#define TRUNC(n) if (snapend - bp + 1 <= n) goto trunc;

#define FIDOUT() { unsigned long n1, n2, n3; \
                   TRUNC(sizeof(int32_t) * 3); \
                   n1 = ntohl(*((int *) bp)); \
                   bp += sizeof(int32_t); \
                   n2 = ntohl(*((int *) bp)); \
                   bp += sizeof(int32_t); \
                   n3 = ntohl(*((int *) bp)); \
                   bp += sizeof(int32_t); \
                   PRINTF(" fid %d/%d/%d", (int) n1, (int) n2, (int) n3); \
                 }

#define STROUT(MAX) { int i; \
                      TRUNC(sizeof(int32_t)); \
                      i = (int) ntohl(*((int *) bp)); \
                      bp += sizeof(int32_t); \
                      TRUNC(i); \
                      strncpy(s, bp, min(MAX, i)); \
                      s[i] = '\0'; \
                      PRINTF(" \"%s\"", s); \
                      bp += ((i + sizeof(int32_t) - 1) / sizeof(int32_t)) * sizeof(int32_t); \
                    }

#define INTOUT()  { int i; \
                    TRUNC(sizeof(int32_t)); \
                    i = (int) ntohl(*((int *) bp)); \
                    bp += sizeof(int32_t); \
                    PRINTF(" %d", i); \
                  }

#define UINTOUT() { unsigned long i; \
                    TRUNC(sizeof(int32_t)); \
                    i = ntohl(*((int *) bp)); \
                    bp += sizeof(int32_t); \
                    PRINTF(" %lu", i); \
                  }

#define DATEOUT() { time_t t; struct tm *tm; char str[256]; \
                    TRUNC(sizeof(int32_t)); \
                    t = (time_t) ntohl(*((int *) bp)); \
                    bp += sizeof(int32_t); \
                    tm = localtime(&t); \
                    strftime(str, 256, "%Y/%m/%d %T", tm); \
                    PRINTF(" %s", str); \
                  }

#define STOREATTROUT() { \
        unsigned long mask, i; \
        TRUNC ((sizeof(int32_t)*6)); \
        mask = ntohl(*((int *) bp)); bp += sizeof(int32_t); \
        if (mask) \
           PUTS (" StoreStatus"); \
        if (mask & 1) { \
           PUTS(" date"); \
           DATEOUT();     \
        } \
        else \
          bp += sizeof(int32_t); \
        i = ntohl(*((int *) bp));   \
        bp += sizeof(int32_t); \
        if (mask & 2)           \
           PRINTF (" owner %lu", i);  \
        i = ntohl(*((int32_t *) bp)); \
        bp += sizeof(int32_t); \
        if (mask & 4)           \
           PRINTF (" group %lu", i); \
        i = ntohl(*((int32_t *) bp)); \
        bp += sizeof(int32_t); \
        if (mask & 8)           \
           PRINTF (" mode %lo", i & 07777); \
        i = ntohl(*((int32_t *) bp));        \
        bp += sizeof(int32_t); \
        if (mask & 16)          \
           PRINTF (" segsize %lu", i); \
        /* undocumented in 3.3 docu */ \
        if (mask & 1024)                \
           PUTS (" fsync");  \
      }

#define UBIK_VERSIONOUT() { \
        int32_t epoch, counter; \
        TRUNC (sizeof(int32_t) * 2); \
        epoch = ntohl(*((int *) bp)); \
        bp += sizeof(int32_t); \
        counter = ntohl(*((int *) bp)); \
        bp += sizeof(int32_t); \
        PRINTF (" %d.%d", epoch, counter); \
      }

#define AFSUUIDOUT() { \
        u_int32_t temp; \
        int i; \
        TRUNC (11*sizeof(u_int32_t)); \
        temp = ntohl(*((int *) bp)); \
        bp += sizeof(u_int32_t); \
        PRINTF (" %08x", temp); \
        temp = ntohl(*((int *) bp)); \
        bp += sizeof(u_int32_t); \
        PRINTF ("%04x", temp); \
        temp = ntohl(*((int *) bp)); \
        bp += sizeof(u_int32_t); \
        PRINTF ("%04x", temp); \
        for (i = 0; i < 8; i++) { \
           temp = ntohl(*((int *) bp)); \
           bp += sizeof(u_int32_t); \
           PRINTF("%02x", (unsigned char) temp); \
        } \
      }

/*
 * This is the sickest one of all
 */   
#define VECOUT(MAX) { \
        char *sp; \
        int k; \
        TRUNC (MAX * sizeof(int32_t)); \
        sp = s; \
        for (k = 0; k < MAX; k++) { \
           *sp++ = (char) ntohl(*((int *) bp)); \
           bp += sizeof(int32_t); \
        } \
        s[MAX] = '\0'; \
        PRINTF (" \"%s\"", s); \
      }

/*
 * Handle calls to the AFS file service (fs)
 */ 
void fs_print (const u_char * bp, int length)
{
  int   fs_op;
  char  s[AFSNAMEMAX];
  DWORD i;

  if (length <= sizeof(struct rx_header))
     return;

  if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t))
     goto trunc;

  /*
   * Print out the afs call we're invoking.  The table used here was
   * gleaned from fsint/afsint.xg
   */
  fs_op = ntohl (*((int *) (bp + sizeof(struct rx_header))));

  PRINTF (" fs call %s", tok2str (fs_req, "op#%d", fs_op));

  /*
   * Print out arguments to some of the AFS calls.  This stuff is
   * all from afsint.xg
   */
  bp += sizeof(struct rx_header) + 4;

  /*
   * Sigh.  This is gross.  Ritchie forgive me.
   */
  switch (fs_op)
  {
    case 130:                /* Fetch data */
         FIDOUT();
         PUTS (" offset");
         UINTOUT();
         PUTS (" length");
         UINTOUT();
         break;
    case 131:                /* Fetch ACL */
    case 132:                /* Fetch Status */
    case 143:                /* Old set lock */
    case 144:                /* Old extend lock */
    case 145:                /* Old release lock */
    case 156:                /* Set lock */
    case 157:                /* Extend lock */
    case 158:                /* Release lock */
         FIDOUT();
         break;
    case 135:                /* Store status */
         FIDOUT();
         STOREATTROUT();
         break;
    case 133:                /* Store data */
         FIDOUT();
         STOREATTROUT();
         PUTS (" offset");
         UINTOUT();
         PUTS (" length");
         UINTOUT();
         PUTS (" flen");
         UINTOUT();
         break;
    case 134:                /* Store ACL */
         {
           char a[AFSOPAQUEMAX];

           FIDOUT();
           TRUNC (4);
           i = ntohl (*((int *) bp));
           bp += sizeof(int32_t);
           TRUNC (i);
           strncpy (a, bp, min (AFSOPAQUEMAX, i));
           a[i] = '\0';
           acl_print ((u_char *) a, (u_char *) a + i);
           break;
         }
    case 137:                /* Create file */
    case 141:                /* MakeDir */
         FIDOUT();
         STROUT (AFSNAMEMAX);
         STOREATTROUT();
         break;
    case 136:                /* Remove file */
    case 142:                /* Remove directory */
         FIDOUT();
         STROUT (AFSNAMEMAX);
         break;
    case 138:                /* Rename file */
         PUTS (" old");
         FIDOUT();
         STROUT (AFSNAMEMAX);
         PUTS (" new");
         FIDOUT();
         STROUT (AFSNAMEMAX);
         break;
    case 139:                /* Symlink */
         FIDOUT();
         STROUT (AFSNAMEMAX);
         PUTS (" link to");
         STROUT (AFSNAMEMAX);
         break;
    case 140:                /* Link */
         FIDOUT();
         STROUT (AFSNAMEMAX);
         PUTS (" link to");
         FIDOUT();
         break;
    case 148:                /* Get volume info */
         STROUT (AFSNAMEMAX);
         break;
    case 149:                /* Get volume stats */
    case 150:                /* Set volume stats */
         PUTS (" volid");
         UINTOUT();
         break;
    case 154:                /* New get volume info */
         PUTS (" volname");
         STROUT (AFSNAMEMAX);
         break;
    case 155:                /* Bulk stat */
         {
           unsigned long j;

           TRUNC (4);
           j = ntohl (*((int *) bp));
           bp += sizeof(int32_t);

           for (i = 0; i < j; i++)
           {
             FIDOUT();
             if (i != j - 1)
               PUTCHAR (',');
           }
           if (j == 0)
             PUTS (" <none!>");
         }
  }

  return;

trunc:
  PUTS (" [|fs]");
}

/*
 * Handle replies to the AFS file service
 */

static void fs_reply_print (const u_char * bp, int length, int32_t opcode)
{
  struct   rx_header *rxh;
  unsigned long i;
  char     s[AFSNAMEMAX];

  if (length <= sizeof(struct rx_header))
    return;

  rxh = (struct rx_header *) bp;

  /*
   * Print out the afs call we're invoking.  The table used here was
   * gleaned from fsint/afsint.xg
   */
  PRINTF (" fs reply %s", tok2str (fs_req, "op#%d", opcode));

  bp += sizeof(struct rx_header);

  /*
   * If it was a data packet, interpret the response
   */
  if (rxh->type == RX_PACKET_TYPE_DATA)
    switch (opcode)
    {
      case 131:              /* Fetch ACL */
           {
             char a[AFSOPAQUEMAX];

             TRUNC (4);
             i = ntohl (*((int *) bp));
             bp += sizeof(int32_t);
             TRUNC (i);
             strncpy (a, bp, min (AFSOPAQUEMAX, i));
             a[i] = '\0';
             acl_print ((u_char *) a, (u_char *) a + i);
             break;
           }
      case 137:              /* Create file */
      case 141:              /* MakeDir */
           PUTS (" new");
           FIDOUT();
           break;
      case 151:              /* Get root volume */
           PUTS (" root volume");
           STROUT (AFSNAMEMAX);
           break;
      case 153:              /* Get time */
           DATEOUT();
           break;
    }
  else
  {
    /*
     * Otherwise, just print out the return code
     */
    PUTS (" errcode");
    INTOUT();
  }

  return;

trunc:
  PUTS (" [|fs]");
}

/*
 * Print out an AFS ACL string.  An AFS ACL is a string that has the
 * following format:
 *
 * <positive> <negative>
 * <uid1> <aclbits1>
 * ....
 * 
 * "positive" and "negative" are integers which contain the number of
 * positive and negative ACL's in the string.  The uid/aclbits pair are
 * ASCII strings containing the UID/PTS record and and a ascii number
 * representing a logical OR of all the ACL permission bits
 */
static void acl_print (u_char * s, u_char * end)
{
  int pos, neg, acl;
  int n, i;
  char user[128];

  if (sscanf ((char *) s, "%d %d\n%n", &pos, &neg, &n) != 2)
     return;

  s += n;

  if (s > end)
    return;

  /*
   * This wacky order preserves the order used by the "fs" command
   */

#define ACLOUT(acl) \
        if (acl & PRSFS_READ)       PUTCHAR ('r'); \
        if (acl & PRSFS_LOOKUP)     PUTCHAR ('l'); \
        if (acl & PRSFS_INSERT)     PUTCHAR ('i'); \
        if (acl & PRSFS_DELETE)     PUTCHAR ('d'); \
        if (acl & PRSFS_WRITE)      PUTCHAR ('w'); \
        if (acl & PRSFS_LOCK)       PUTCHAR ('k'); \
        if (acl & PRSFS_ADMINISTER) PUTCHAR ('a');

  for (i = 0; i < pos; i++)
  {
    if (sscanf ((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
      return;
    s += n;
    PRINTF (" +{%s ", user);
    ACLOUT (acl);
    PUTCHAR ('}');
    if (s > end)
      return;
  }

  for (i = 0; i < neg; i++)
  {
    if (sscanf ((char *) s, "%s %d\n%n", user, &acl, &n) != 2)
      return;
    s += n;
    PRINTF (" -{%s ", user);
    ACLOUT (acl);
    PUTCHAR ('}');
    if (s > end)
      return;
  }
}

#undef ACLOUT

/*
 * Handle calls to the AFS callback service
 */

static void cb_print (const u_char * bp, int length)
{
  int      cb_op;
  unsigned long i;

  if (length <= sizeof(struct rx_header))
     return;

  if (snapend - bp + 1 <= sizeof(struct rx_header) + sizeof(int32_t))
     goto trunc;

  /*
   * Print out the afs call we're invoking.  The table used here was
   * gleaned from fsint/afscbint.xg
   */
  cb_op = ntohl (*((int *) (bp + sizeof(struct rx_header))));

  PRINTF (" cb call %s", tok2str (cb_req, "op#%d", cb_op));

  bp += sizeof(struct rx_header) + 4;

  /*
   * Print out the afs call we're invoking.  The table used here was
   * gleaned from fsint/afscbint.xg
   */
  switch (cb_op)
  {
    case 204:                /* Callback */
         {
           unsigned long j, t;

           TRUNC (4);
           j = ntohl (*((int *) bp));
           bp += sizeof(int32_t);

           for (i = 0; i < j; i++)
           {
             FIDOUT();
             if (i != j - 1)
                PUTCHAR (',');
           }

           if (j == 0)
             PUTS (" <none!>");

           j = ntohl (*((int *) bp));
           bp += sizeof(int32_t);

           if (j != 0)
             PUTS (";");

           for (i = 0; i < j; i++)
           {
             PUTS (" ver");
             INTOUT();
             PUTS (" expires");
             DATEOUT();
             TRUNC (4);
             t = ntohl (*((int *) bp));
             bp += sizeof(int32_t);
             tok2str (cb_types, "type %d", t);
           }
         }
    case 214:
         {
           PUTS (" afsuuid");
           AFSUUIDOUT();
           break;
         }
  }
  return;

trunc:
  PUTS (" [|cb]");
}

/*
 * Handle replies to the AFS Callback Service
 */
static void cb_reply_print (const u_char * bp, int length, int32_t opcode)
{
  struct rx_header *rxh;

  if (length <= sizeof(struct rx_header))
     return;

  rxh = (struct rx_header *) bp;

  /*
   * Print out the afs call we're invoking.  The table used here was
   * gleaned from fsint/afscbint.xg
   */
  PRINTF (" cb reply %s", tok2str (cb_req, "op#%d", opcode));

  bp += sizeof(struct rx_header);

  /*
   * If it was a data packet, interpret the response.
   */
  if (rxh->type == RX_PACKET_TYPE_DATA)
    switch (opcode)
    {
      case 213:              /* InitCallBackState3 */
           AFSUUIDOUT();
           break;
      default:
           ;
    }
  else
  {
    /*
     * Otherwise, just print out the return code
     */
    PUTS (" errcode");
    INTOUT();
  }
  return;

⌨️ 快捷键说明

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