Changeset 4867

Show
Ignore:
Timestamp:
05/31/09 18:00:15 (4 years ago)
Author:
ignotus
Message:

Improve umit.zion.scan.sniff.Packet.get_field() method.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branch/zion/umit/zion/scan/sniff.py

    r4866 r4867  
    253253        return "\n".join(s) 
    254254 
     255FRAME_TYPES = {'sll': SLL, 
     256               'ether': Ethernet, 
     257               'ipv4': IPv4, 
     258               'ipv6': IPv6, 
     259               'tcp': TCP} 
     260 
    255261class Packet(object): 
    256262    """ 
     
    282288        # Disassembling first frame. 
    283289        # There are two options to make this work right: 
     290        # 
    284291        #   1. Disassembly the link layer and see what the next protocol on 
    285292        #      their data fields; 
    286293        #   2. Ignore the first `n' bytes of link layer data. Where `n' stands 
    287294        #      for size of link layer protocol header. 
     295        # 
    288296        # The second one can fail when the link layer protocol has a variable 
    289297        # header length. So, is not correct do this way. Moreover, we can be 
     
    346354        proto, attr = field.split('.') 
    347355 
    348         for p in self.__packet: 
    349             if proto == 'ether' and type(p) == Ethernet and hasattr(p, attr): 
    350                 return getattr(p, attr) 
    351             elif proto == 'ipv4' and type(p) == IPv4 and hasattr(p, attr): 
    352                 return getattr(p, attr) 
    353             elif proto == 'ipv6' and type(p) == IPv6 and hasattr(p, attr): 
    354                 return getattr(p, attr) 
    355             elif proto == 'tcp' and type(p) == TCP and hasattr(p, attr): 
    356                 return getattr(p, attr) 
     356        if proto in FRAME_TYPES.keys(): 
     357            for p in self.__packet: 
     358                if hasattr(p, attr) and type(p) == FRAME_TYPES[proto]: 
     359                    return getattr(p, attr) 
    357360 
    358361        return None