Home | Trees | Indices | Help |
|
---|
|
1 # $Id: cdp.py 23 2006-11-08 15:45:33Z dugsong $ 2 # -*- coding: utf-8 -*- 3 """Cisco Discovery Protocol.""" 4 from __future__ import absolute_import 5 6 import struct 7 8 from . import dpkt 9 10 CDP_DEVID = 1 # string 11 CDP_ADDRESS = 2 12 CDP_PORTID = 3 # string 13 CDP_CAPABILITIES = 4 # 32-bit bitmask 14 CDP_VERSION = 5 # string 15 CDP_PLATFORM = 6 # string 16 CDP_IPPREFIX = 7 17 18 CDP_VTP_MGMT_DOMAIN = 9 # string 19 CDP_NATIVE_VLAN = 10 # 16-bit integer 20 CDP_DUPLEX = 11 # 8-bit boolean 21 CDP_TRUST_BITMAP = 18 # 8-bit bitmask0x13 22 CDP_UNTRUST_COS = 19 # 8-bit port 23 CDP_SYSTEM_NAME = 20 # string 24 CDP_SYSTEM_OID = 21 # 10-byte binary string 25 CDP_MGMT_ADDRESS = 22 # 32-bit number of addrs, Addresses 26 CDP_LOCATION = 23 # string 27 2830 """Cisco Discovery Protocol. 31 32 See more about the BGP on \ 33 https://en.wikipedia.org/wiki/Cisco_Discovery_Protocol 34 35 Attributes: 36 __hdr__: Header fields of CDP. 37 #TODO 38 """ 39 40 __hdr__ = ( 41 ('version', 'B', 2), 42 ('ttl', 'B', 180), 43 ('sum', 'H', 0) 44 ) 4511247 # XXX - only handle NLPID/IP for now 48 __hdr__ = ( 49 ('ptype', 'B', 1), # protocol type (NLPID) 50 ('plen', 'B', 1), # protocol length 51 ('p', 'B', 0xcc), # IP 52 ('alen', 'H', 4) # address length 53 ) 545860 __hdr__ = ( 61 ('type', 'H', 0), 62 ('len', 'H', 4) 63 ) 649366 dpkt.Packet.unpack(self, buf) 67 self.data = self.data[:self.len - 4] 68 if self.type == CDP_ADDRESS: 69 n = struct.unpack('>I', self.data[:4])[0] 70 buf = self.data[4:] 71 l = [] 72 for i in range(n): 73 a = CDP.Address(buf) 74 l.append(a) 75 buf = buf[len(a):] 76 self.data = l7779 if self.type == CDP_ADDRESS: 80 n = 4 + sum(map(len, self.data)) 81 else: 82 n = len(self.data) 83 return self.__hdr_len__ + n8495 dpkt.Packet.unpack(self, buf) 96 buf = self.data 97 l = [] 98 while buf: 99 tlv = self.TLV(buf) 100 l.append(tlv) 101 buf = buf[len(tlv):] 102 self.data = l103 106
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Apr 29 23:17:55 2019 | http://epydoc.sourceforge.net |