📄 packetcdp.cs
字号:
using System;
using System.Windows.Forms;
namespace MyClasses
{
public class PacketCDP
{
public struct PACKET_CDP_ADDRESS
{
public byte ProtocolType;
public string ProtocolTypeStr;
public byte ProtocolLength;
public byte Protocol;
public string ProtocolStr;
public ushort AddressLength;
public string IpAddress;
}
public struct PACKET_CDP_ADDRESSES
{
public ushort Type;
public ushort Length;
public uint AddressCount;
public PACKET_CDP_ADDRESS [] IpAddresses;
}
public struct PACKET_CDP_CONTENTS
{
public ushort Type;
public ushort Length;
public string Name;
}
public struct PACKET_CDP
{
public byte Version;
public byte TTL;
public ushort Checksum;
public PACKET_CDP_CONTENTS DeviceId;
public PACKET_CDP_CONTENTS SoftwareVersion;
public PACKET_CDP_CONTENTS Platform;
public PACKET_CDP_ADDRESSES Addresses;
public PACKET_CDP_CONTENTS PortId;
public ushort CapabilitiesType;
public ushort CapabilitiesLength;
public uint CapabilitiesFlag;
public string CapabilitiesFlagStr;
public PACKET_CDP_CONTENTS VTP;
public PACKET_CDP_CONTENTS Duplex;
}
public PacketCDP()
{
}
public static string GetTypeList( ushort b )
{
int i = 0;
string [] TypeList = new string[256];
for( i = 0; i < 256; i ++ )
TypeList[i] = "Unknown";
TypeList[Const.TYPE_DEVICE_ID] = "Device ID"; TypeList[Const.TYPE_ADDRESS] = "Addresses"; TypeList[Const.TYPE_PORT_ID] = "Port ID"; TypeList[Const.TYPE_CAPABILITIES] = "Capabilities"; TypeList[Const.TYPE_IOS_VERSION] = "Software version"; TypeList[Const.TYPE_PLATFORM] = "Platform"; TypeList[Const.TYPE_IP_PREFIX] = "IP Prefix (used for ODR)"; TypeList[Const.TYPE_VTP_MGMT_DOMAIN] = "VTP Management Domain"; TypeList[Const.TYPE_NATIVE_VLAN] = "Native VLAN"; TypeList[Const.TYPE_DUPLEX] = "Duplex";
return TypeList[b];
}
public static string GetProtocolSubTypeList( byte b )
{
int i = 0;
string [] ProtocolSubTypeList = new string[256];
for( i = 0; i < 256; i ++ )
ProtocolSubTypeList[i] = "Unknown";
ProtocolSubTypeList[Const.NLPID_NULL] = "NULL"; ProtocolSubTypeList[Const.NLPID_IPI_T_70] = "IP T.70"; ProtocolSubTypeList[Const.NLPID_SPI_X_29] = "SPI X.29"; ProtocolSubTypeList[Const.NLPID_X_633] = "X.633"; ProtocolSubTypeList[Const.NLPID_Q_931] = "Q931"; ProtocolSubTypeList[Const.NLPID_Q_2931] = "Q2931"; ProtocolSubTypeList[Const.NLPID_Q_2119] = "Q2119"; ProtocolSubTypeList[Const.NLPID_SNAP] = "SNAP"; ProtocolSubTypeList[Const.NLPID_ISO8473_CLNP] = "ISO 8473 CLNP"; ProtocolSubTypeList[Const.NLPID_ISO9542_ESIS] = "ISO 9542 ESIS"; ProtocolSubTypeList[Const.NLPID_ISO10589_ISIS] = "ISO 10589 ISIS"; ProtocolSubTypeList[Const.NLPID_ISO10747_IDRP] = " ISO 10747 IDRP"; ProtocolSubTypeList[Const.NLPID_ISO9542X25_ESIS] = "ISO 9542 X.25 ESIS"; ProtocolSubTypeList[Const.NLPID_ISO10030] = "ISO 10030"; ProtocolSubTypeList[Const.NLPID_ISO11577] = "ISO 11577"; ProtocolSubTypeList[Const.NLPID_IP6] = "IP.6"; ProtocolSubTypeList[Const.NLPID_COMPRESSED] = "COMPRESSED"; ProtocolSubTypeList[Const.NLPID_SNDCF] = "SNDCF"; ProtocolSubTypeList[Const.NLPID_IP] = "IP"; ProtocolSubTypeList[Const.NLPID_PPP] = "PPP";
return ProtocolSubTypeList[b];
}
public static string GetProtocolTypeList( byte b )
{
int i = 0;
string [] ProtocolTypeList = new string[256];
for( i = 0; i < 256; i ++ )
ProtocolTypeList[i] = "Unknown";
ProtocolTypeList[Const.PROTO_TYPE_NLPID] = "NLPID"; ProtocolTypeList[Const.PROTO_TYPE_IEEE_802_2] = "802.2";
return ProtocolTypeList[b];
}
public static bool Parser( ref TreeNodeCollection mNode,
byte [] PacketData ,
ref int Index ,
ref ListViewItem LItem )
{
TreeNode mNodex;
TreeNode mNode1;
TreeNode mNode2;
string Tmp = "";
uint ui = 0;
int i = 0;
int kk = 0;
PACKET_CDP PCdp;
mNodex = new TreeNode();
mNodex.Text = "CDP ( Cisco Discovery Protocol )";
kk = Index;
try
{
PCdp.Version = PacketData[ Index++ ];
Tmp = "Version :" + Function.ReFormatString( PCdp.Version , null );
mNodex.Nodes.Add( Tmp );
Function.SetPosition( ref mNodex , Index - 1 , 1 , false );
PCdp.TTL = PacketData[ Index++ ];
Tmp = "TTL :" + Function.ReFormatString( PCdp.TTL , null );
mNodex.Nodes.Add( Tmp );
Function.SetPosition( ref mNodex , Index - 1 , 1 , false );
PCdp.Checksum = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Checksum :" + Function.ReFormatString( PCdp.Checksum , null );
mNodex.Nodes.Add( Tmp );
Function.SetPosition( ref mNodex , Index - 2 , 2 , false );
// Device Id Section ................
mNode1 = new TreeNode();
mNode1.Text = "Device Id";
PCdp.DeviceId.Type = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Type :" + Function.ReFormatString( PCdp.DeviceId.Type , GetTypeList(PCdp.DeviceId.Type) );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.DeviceId.Length = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Length :" + Function.ReFormatString( PCdp.DeviceId.Length , null );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.DeviceId.Name = "";
for( i = 0; i < PCdp.DeviceId.Length - 4; i ++ )
PCdp.DeviceId.Name += (char) PacketData[ Index++ ];
Tmp = "Name : " + PCdp.DeviceId.Name;
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - PCdp.DeviceId.Length + 4 , PCdp.DeviceId.Length - 4 , false );
Function.SetPosition( ref mNode1 , Index - PCdp.DeviceId.Length , PCdp.DeviceId.Length , true );
mNodex.Nodes.Add( mNode1 );
// Software Version Section ................
mNode1 = new TreeNode();
mNode1.Text = "Software Version";
PCdp.SoftwareVersion.Type = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Type :" + Function.ReFormatString( PCdp.SoftwareVersion.Type , GetTypeList(PCdp.SoftwareVersion.Type) );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.SoftwareVersion.Length = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Length :" + Function.ReFormatString( PCdp.SoftwareVersion.Length , null );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.SoftwareVersion.Name = "";
for( i = 0; i < PCdp.SoftwareVersion.Length - 4; i ++ )
PCdp.SoftwareVersion.Name += (char) PacketData[ Index++ ];
Tmp = "Name : " + PCdp.SoftwareVersion.Name;
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - PCdp.SoftwareVersion.Length + 4 , PCdp.SoftwareVersion.Length - 4 , false );
Function.SetPosition( ref mNode1 , Index - PCdp.SoftwareVersion.Length , PCdp.SoftwareVersion.Length , true );
mNodex.Nodes.Add( mNode1 );
// Platform Section ................
mNode1 = new TreeNode();
mNode1.Text = "Platform";
PCdp.Platform.Type = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Type :" + Function.ReFormatString( PCdp.Platform.Type , GetTypeList(PCdp.Platform.Type) );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.Platform.Length = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Length :" + Function.ReFormatString( PCdp.Platform.Length , null );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.Platform.Name = "";
for( i = 0; i < PCdp.Platform.Length - 4; i ++ )
PCdp.Platform.Name += (char) PacketData[ Index++ ];
Tmp = "Name : " + PCdp.Platform.Name;
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - PCdp.Platform.Name.Length , PCdp.Platform.Name.Length , false );
Function.SetPosition( ref mNode1 , Index - PCdp.Platform.Name.Length - 4 , PCdp.Platform.Name.Length + 4 , true );
mNodex.Nodes.Add( mNode1 );
// Addresses Section ................
mNode1 = new TreeNode();
mNode1.Text = "Addresses";
PCdp.Addresses.Type = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Type :" + Function.ReFormatString( PCdp.Addresses.Type , GetTypeList(PCdp.Addresses.Type) );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.Addresses.Length = Function.Get2Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Length :" + Function.ReFormatString( PCdp.Addresses.Length , null );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 2 , 2 , false );
PCdp.Addresses.AddressCount = Function.Get4Bytes( PacketData , ref Index , Const.NORMAL );
Tmp = "Number of Addresses :" + Function.ReFormatString( PCdp.Addresses.AddressCount , null );
mNode1.Nodes.Add( Tmp );
Function.SetPosition( ref mNode1 , Index - 4 , 4 , false );
Function.SetPosition( ref mNode1 , Index - 8 , 8 + (int) PCdp.Addresses.AddressCount * 9 , true );
if( PCdp.Addresses.AddressCount > 0 )
{
PCdp.Addresses.IpAddresses = new PACKET_CDP_ADDRESS[PCdp.Addresses.AddressCount];
for( i = 0; i < PCdp.Addresses.AddressCount; i ++ )
{
mNode2 = new TreeNode();
Function.SetPosition( ref mNode2 , Index , 9 , true );
PCdp.Addresses.IpAddresses[i].ProtocolType = PacketData[ Index++ ];
Tmp = "Protocol Type :" + Function.ReFormatString( PCdp.Addresses.IpAddresses[i].ProtocolType , GetProtocolTypeList(PCdp.Addresses.IpAddresses[i].ProtocolType) );
mNode2.Nodes.Add( Tmp );
Function.SetPosition( ref mNode2 , Index - 1 , 1 , false );
if( PCdp.Addresses.IpAddresses[i].ProtocolType == 1 ) PCdp.Addresses.IpAddresses[i].ProtocolTypeStr = "NLPID";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -