예제 #1
0
        public CDPType0002(CDPMessage cdp)
        {
            int pos = 0;
            int len = 0;

            Byte[] d = null;

            type = cdp.Data[pos++];

            len      = cdp.Data[pos++];
            protocol = 0;
            for (int i = 0; i < len; i++)
            {
                protocol = protocol << 8 | cdp.Data[pos++];
            }

            len = cdp.Data[pos++];
            Array.Resize(ref d, len);
            for (int i = 0; i < len; i++)
            {
                d[i] = cdp.Data[pos++];
            }

            address = d;
        }
예제 #2
0
        public CDPType0004(CDPMessage cdp)
        {
            int pos = 0;

            Byte[] d = null;

            Array.Resize(ref d, cdp.Size);
            for (int i = 0; i < cdp.Size; i++)
            {
                d[i] = cdp.Data[pos++];
            }

            data = d;
        }
예제 #3
0
        public CDPDecoder(Packet packet)
        {
            CDPMessage[] data = null;
            int Pos = 22;
            int Count = 0;
            Version = packet[Pos++];
            TTL = packet[Pos++];
            CheckSum = (UInt16)((UInt16)(packet[Pos++] << 8) | (UInt16)(packet[Pos++]));

            while (Pos < packet.Length)
            {
                Array.Resize(ref data, Count + 1);
                data[Count] = new CDPMessage(Pos, packet);
                //MessageBox.Show("Message #" + Count + ", CDP Message : " + data[Count].typeName() + ", Length : " + data[Count].Size.ToString());
                Pos = Pos + data[Count].Size + 4;
                Count++;
            }

            Data = data;
        }
예제 #4
0
        public CDPDecoder(Packet packet)
        {
            CDPMessage[] data  = null;
            int          Pos   = 22;
            int          Count = 0;

            Version  = packet[Pos++];
            TTL      = packet[Pos++];
            CheckSum = (UInt16)((UInt16)(packet[Pos++] << 8) | (UInt16)(packet[Pos++]));

            while (Pos < packet.Length)
            {
                Array.Resize(ref data, Count + 1);
                data[Count] = new CDPMessage(Pos, packet);
                //MessageBox.Show("Message #" + Count + ", CDP Message : " + data[Count].typeName() + ", Length : " + data[Count].Size.ToString());
                Pos = Pos + data[Count].Size + 4;
                Count++;
            }

            Data = data;
        }
예제 #5
0
 public CDPType0001(CDPMessage cdp)
 {
     data = Encoding.Default.GetString(cdp.Data, 0, cdp.Size);
 }
예제 #6
0
 public CDPType0009(CDPMessage cdp)
 {
     data = Encoding.Default.GetString(cdp.Data, 0, cdp.Size);
 }
예제 #7
0
        public CDPType0004(CDPMessage cdp)
        {
            int pos = 0;
            Byte[] d = null;

            Array.Resize(ref d, cdp.Size);
            for (int i = 0; i < cdp.Size; i++)
            {
                d[i] = cdp.Data[pos++];
            }

            data = d;
        }
예제 #8
0
        public CDPType0002(CDPMessage cdp)
        {
            int pos = 0;
            int len = 0;
            Byte[] d = null;

            type = cdp.Data[pos++];

            len = cdp.Data[pos++];
            protocol = 0;
            for (int i = 0; i < len; i++)
            {
                protocol = protocol << 8 | cdp.Data[pos++];
            }

            len = cdp.Data[pos++];
            Array.Resize(ref d, len);
            for (int i = 0; i < len; i++)
            {
                d[i] = cdp.Data[pos++];
            }

            address = d;
        }
예제 #9
0
        public CDPToText(CDPMessage[] cdpMessages)
        {
            StringBuilder sb = new StringBuilder();

            foreach (CDPMessage cdpMessage in cdpMessages)
            {
                switch (cdpMessage.Type)
                {
                    case 0x0001:
                        sb.Append("Device ID : " + Encoding.Default.GetString(cdpMessage.Data, 0, cdpMessage.Size) + "\n\n");

                        break;
                    case 0x0002:
                        sb.Append("Addresses : ");
                        sb.Append(decodeAddress("Addresses : ", cdpMessage.Data, cdpMessage.Size));
                        break;
                    case 0x0003:
                        sb.Append("Port ID : " + Encoding.Default.GetString(cdpMessage.Data, 0, cdpMessage.Size) + "\n\n");
                        break;
                    case 0x0004:
                        {
                            string st = "\n" + new String(' ', 15);
                            sb.Append("Capabilities : ");
                            for (int i = 0; i < cdpMessage.Size; i++)
                            {
                                if (byteCmp(cdpMessage.Data[i], 0x01))
                                {
                                    sb.Append("Performs level 3 routing for at least one network layer protocol." + st);
                                }
                                if (byteCmp(cdpMessage.Data[i], 0x02))
                                {
                                    sb.Append("Performs level 2 transparent bridging." + st);
                                }
                                if (byteCmp(cdpMessage.Data[i], 0x04))
                                {
                                    sb.Append("Performs level 2 source-route bridging." + st);
                                }
                                if (byteCmp(cdpMessage.Data[i], 0x08))
                                {
                                    sb.Append("Performs level 2 switching." + st);
                                }
                                if (byteCmp(cdpMessage.Data[i], 0x10))
                                {
                                    sb.Append("Sends and receives packets for at least one network layer protocol." + st);
                                }
                                if (byteCmp(cdpMessage.Data[i], 0x20))
                                {
                                    sb.Append("The bridge or switch does not forward IGMP." + st);
                                }
                                if (byteCmp(cdpMessage.Data[i], 0x40))
                                {
                                    sb.Append("Provides level 1 functionality." + st);
                                }
                            }
                            sb.Append("\n");
                        }
                        break;
                    case 0x0005:
                        sb.Append("Software version:\n\n" + Encoding.Default.GetString(cdpMessage.Data, 0, cdpMessage.Size) + "\n\n");
                        break;
                    case 0x0006:
                        sb.Append("Platform: " + Encoding.Default.GetString(cdpMessage.Data, 0, cdpMessage.Size) + "\n\n");
                        break;
                    case 0x0007:
                        sb.Append("IP Prefix : ");
                        sb.Append(hexDump(new String(' ', 12), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n");
                        break;
                    case 0x0008:
                        sb.Append("Protocol Hello : ");
                        sb.Append(hexDump(new String(' ', 17), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n");
                        break;
                    case 0x0009:
                        sb.Append("VTP Domain : " + Encoding.Default.GetString(cdpMessage.Data, 0, cdpMessage.Size) + "\n\n");
                        break;
                    case 0x000a:
                        {
                            UInt64 vlan = 0;
                            sb.Append("Native VLAN : ");
                            for (int i = 0; i < cdpMessage.Size; i++)
                            {
                                vlan = (vlan << 8) | cdpMessage.Data[i];
                            }
                            sb.Append(vlan.ToString() + "\n\n");
                        }
                        break;
                    case 0x000b:
                        sb.Append("Duplex : ");
                        if (cdpMessage.Data[0] == 0)
                        {
                            sb.Append("Half\n\n");
                        }
                        else
                        {
                            sb.Append("Full\n\n");
                        }
                        break;
                    case 0x000e:
                        {
                            int index = cdpMessage.Data[0], count = 0;
                            sb.Append("VOIP Vlan : ");

                            for (int i = 1; i < cdpMessage.Size; i += 2)
                            {
                                int vlan = 0;
                                count++;
                                vlan = (cdpMessage.Data[i] << 8) | cdpMessage.Data[i + 1];
                                sb.Append(vlan.ToString());
                                if (count < index)
                                {
                                    sb.Append(", ");
                                }
                            }
                            sb.Append("\n\n");
                        }
                        break;
                    case 0x000f:
                        sb.Append("VOIP Vlan Query : ");
                        sb.Append(hexDump(new String(' ', 18), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0010:
                        sb.Append("Power : ");
                        sb.Append(hexDump(new String(' ', 8), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0011:
                        sb.Append("MTU : ");
                        sb.Append(hexDump(new String(' ', 6), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0012:
                        sb.Append("Trust Bitmap : ");
                        sb.Append(hexDump(new String(' ', 15), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0013:
                        sb.Append("Untrusted COS : ");
                        sb.Append(hexDump(new String(' ', 16), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0014:
                        sb.Append("System Name : " + Encoding.Default.GetString(cdpMessage.Data, 0, cdpMessage.Size) + "\n\n");
                        break;
                    case 0x0015:
                        sb.Append("System ODI : ");
                        sb.Append(hexDump(new String(' ', 13), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0016:
                        sb.Append(decodeAddress("Management Address : ", cdpMessage.Data, cdpMessage.Size));
                        sb.Append("\n\n");
                        break;
                    case 0x0017:
                        sb.Append("Location : ");
                        sb.Append(hexDump(new String(' ', 11), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0018:
                        sb.Append("External Port ID : ");
                        sb.Append(hexDump(new String(' ', 19), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x0019:
                        sb.Append("Power Requested : ");
                        sb.Append(hexDump(new String(' ', 18), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x001a:
                        sb.Append("Power Avalable : ");
                        sb.Append(hexDump(new String(' ', 17), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x001b:
                        sb.Append("Port Unidir : ");
                        sb.Append(hexDump(new String(' ', 14), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x001d:
                        sb.Append("NRGYZ : ");
                        sb.Append(hexDump(new String(' ', 8), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x001f:
                        sb.Append("Spare POE : ");
                        sb.Append(hexDump(new String(' ', 12), cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    case 0x1003:
                        sb.Append("Could someone tell me what this Type (0x1003) is? :\n");
                        sb.Append(hexDump("", cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                    default:
                        sb.Append("Unknown Message (" + cdpMessage.Type.ToString() + ") :\n");
                        sb.Append(hexDump("", cdpMessage.Data, cdpMessage.Size, 8));
                        // XXX TODO Decode Address
                        sb.Append("\n\n");
                        break;
                }
                text = sb.ToString();
            }
        }