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

📄 _stp.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
字号:
/*
 * Copyright (c) 2000 Lennert Buytenhek
 *
 * This software may be distributed either under the terms of the
 * BSD-style license that accompanies tcpdump or the GNU General
 * Public License
 *
 * Format and print IEEE 802.1d spanning tree protocol packets.
 * Contributed by Lennert Buytenhek <buytenh@gnu.org>
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include "interfac.h"
#include "a2name.h"
#include "extract.h"

static __inline void stp_print_bridge_id (const u_char * p)
{
  PRINTF ("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
          p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
}

static void stp_print_config_bpdu (const u_char * p, u_int length)
{
  PUTS ("config ");
  if (p[7] & 1)
     PUTS ("TOP_CHANGE ");
  if (p[7] & 0x80)
     PUTS ("TOP_CHANGE_ACK ");

  stp_print_bridge_id (p + 20);
  PRINTF (".%.2x%.2x root", p[28], p[29]);

  stp_print_bridge_id (p + 8);

  PRINTF (" pathcost %i ",
          (p[16] << 24) | (p[17] << 16) | (p[18] << 8) | p[19]);

  PRINTF ("age %i max %i hello %i fdelay %i", p[30], p[32], p[34], p[36]);
}

static __inline void stp_print_tcn_bpdu (const u_char * p, u_int length)
{
  PUTS ("tcn");
}

/*
 * Print 802.1d packets.
 */
void stp_print (const u_char *p, u_int length)
{
  if (length < 7)
     goto trunc;

  PUTS ("802.1d ");
  if (p[2] != 0x03 || p[3] || p[4] || p[5])
  {
    PUTS ("unknown version");
    return;
  }

  switch (p[6])
  {
    case 0:
         if (length < 10)
            goto trunc;
         stp_print_config_bpdu (p, length);
         break;

    case 1:
         stp_print_tcn_bpdu (p, length);
         break;

    default:
         PRINTF ("unknown type %i\n", p[6]);
         break;
  }
  return;
trunc:
  PRINTF ("[|stp %d]", length);
}

⌨️ 快捷键说明

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