def Decode_Ip_Packet(s):
 d = {}
 d['header_len'] = (ord(s[0]) & 15)
 d['data'] = s[(4 * d['header_len']):]
 return d

def Decode_Ip_Packet ( s ) : d = { } d [ 'header_len' ] = ( ord ( s [ 0 ] ) & 15 ) d [ 'data' ] = s [ ( 4 * d [ 'header_len' ] ) : ] return d
taken from pcredz .