#NEWLINE# def __init__( self , packet , layers = 0 ) : #NEWLINE# #INDENT# magic = struct . unpack ( '!B' , packet [ 0 : 1 ] ) [ 0 ] #NEWLINE# assert ( ( ( magic & 12 ) == 4 ) and ( ( magic & 7 ) > 4 ) ) , 'not an IPv4 packet.' #NEWLINE# fields = struct . unpack ( '!BBHHHBBHII' , packet [ : 20 ] ) #NEWLINE# self . v = ( fields [ 0 ] & 12 ) #NEWLINE# self . hl = ( fields [ 0 ] & 7 ) #NEWLINE# self . tos = fields [ 1 ] #NEWLINE# self . len = fields [ 2 ] #NEWLINE# self . id = fields [ 3 ] #NEWLINE# self . flags = ( fields [ 4 ] >> 13 ) #NEWLINE# self . off = ( fields [ 4 ] & 8191 ) #NEWLINE# self . ttl = fields [ 5 ] #NEWLINE# self . p = fields [ 6 ] #NEWLINE# self . sum = fields [ 7 ] #NEWLINE# self . src = ctypes . c_char_p ( parse_ipv4 ( fields [ 8 ] ) ) #NEWLINE# self . dst = ctypes . c_char_p ( parse_ipv4 ( fields [ 9 ] ) ) #NEWLINE# if ( self . hl > 20 ) : #NEWLINE# #INDENT# start = 21 #NEWLINE# end = ( self . len - 20 ) #NEWLINE# self . opt = binascii . hexlify ( packet [ start : fields ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . opt = b'\x00' #NEWLINE# self . payload = binascii . hexlify ( packet [ 20 : ] ) #NEWLINE# #UNINDENT# self . pad = b'\x00' #NEWLINE# if layers : #NEWLINE# #INDENT# self . load_transport ( layers )