Home | Trees | Indices | Help |
|
---|
|
1 import struct 2 import dpkt, stp, ethernet 35 _typesw = {} 640 41 if __name__ == '__main__': 42 import unittest 438 if self.type == ethernet.ETH_TYPE_8021Q: 9 self.tag, self.type = struct.unpack('>HH', buf[:4]) 10 buf = buf[4:] 11 elif self.type == ethernet.ETH_TYPE_MPLS or \ 12 self.type == ethernet.ETH_TYPE_MPLS_MCAST: 13 # XXX - skip labels 14 for i in range(24): 15 if struct.unpack('>I', buf[i:i+4])[0] & 0x0100: # MPLS_STACK_BOTTOM 16 break 17 self.type = ethernet.ETH_TYPE_IP 18 buf = buf[(i + 1) * 4:] 19 try: 20 self.data = self._typesw[self.type](buf) 21 setattr(self, self.data.__class__.__name__.lower(), self.data) 22 except (KeyError, dpkt.UnpackError): 23 self.data = buf2426 self.data = buf 27 if self.data.startswith('\xaa\xaa'): 28 # SNAP 29 self.type = struct.unpack('>H', self.data[6:8])[0] 30 self._unpack_data(self.data[8:]) 31 else: 32 # non-SNAP 33 dsap = ord(self.data[0]) 34 if dsap == 0x06: # SAP_IP 35 self.data = self.ip = self._typesw[ethernet.ETH_TYPE_IP](self.data[3:]) 36 elif dsap == 0x10 or dsap == 0xe0: # SAP_NETWARE{1,2} 37 self.data = self.ipx = self._typesw[ethernet.ETH_TYPE_IPX](self.data[3:]) 38 elif dsap == 0x42: # SAP_STP 39 self.data = self.stp = stp.STP(self.data[3:])4554 55 unittest.main() 5647 s = '\xaa\xaa\x03\x00\x00\x00\x08\x00\x45\x00\x00\x28\x07\x27\x40\x00\x80\x06\x1d\x39\x8d\xd4\x37\x3d\x3f\xf5\xd1\x69\xc0\x5f\x01\xbb\xb2\xd6\xef\x23\x38\x2b\x4f\x08\x50\x10\x42\x04\xac\x17\x00\x00' 48 49 import ip 50 llc_pkt = LLC(s) 51 ip_pkt = ip.IP(llc_pkt.data) 52 self.failUnless(llc_pkt.type == ethernet.ETH_TYPE_IP) 53 self.failUnless(ip_pkt.dst == '\x3f\xf5\xd1\x69')
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Thu Mar 19 07:50:07 2015 | http://epydoc.sourceforge.net |