<s> from socket import ntohs <EOL> from ctypes import ( c_uint , c_void_p , c_uint32 , c_char_p , ARRAY , c_uint64 , c_int32 , c_uint16 , c_int , <EOL> c_uint8 , c_ulong , c_char , c_ubyte , Structure , c_size_t , c_ssize_t ) <EOL> from enum import Defaults <EOL> def format_structure ( instance ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( instance , "<STR_LIT>" ) : <EOL> out = [ ] <EOL> for field in instance . _fields_ : <EOL> out . append ( "<STR_LIT>" % ( field [ <NUM_LIT:0> ] , getattr ( instance , field [ <NUM_LIT:0> ] , None ) ) ) <EOL> return "<STR_LIT>" . join ( out ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> class PacketHeader ( Structure ) : <EOL> """<STR_LIT>""" <EOL> _fields_ = [ <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , c_char_p ) , <EOL> ( "<STR_LIT>" , c_ulong ) , <EOL> ( "<STR_LIT>" , c_ulong ) , <EOL> ( "<STR_LIT>" , c_ulong ) , <EOL> ( "<STR_LIT>" , c_ulong ) , <EOL> ] <EOL> class IpHeader ( Structure ) : <EOL> """<STR_LIT>""" <EOL> _fields_ = [ <EOL> ( "<STR_LIT>" , c_uint8 ) , <EOL> ( "<STR_LIT>" , c_uint8 ) , <EOL> ( "<STR_LIT>" , c_uint16 ) , <EOL> ( "<STR_LIT>" , c_uint16 ) , <EOL> ( "<STR_LIT>" , c_uint16 ) , <EOL> ( "<STR_LIT>" , c_uint8 ) , <EOL> ( "<STR_LIT>" , c_uint8 ) , <EOL> ( "<STR_LIT>" , c_uint16 ) , <EOL> ( "<STR_LIT>" , c_uint32 ) , <EOL> ( "<STR_LIT>" , c_uint32 ) , <EOL> ] <EOL> def get_total_length ( self ) : <EOL> return ntohs ( self . ip_len ) <EOL> def get_header_length ( self ) : <EOL> return ( self . ip_vhl & <NUM_LIT> ) * <NUM_LIT:4> <EOL> def __str__ ( self ) : <EOL> return format_structure ( self ) <EOL> class ProcInfo ( Structure ) : <EOL> """<STR_LIT>""" <EOL> MAXCOMLEN = <NUM_LIT:32> <EOL> _fields_ = [ <EOL> ( "<STR_LIT>" , c_int32 ) , <EOL> ( "<STR_LIT>" , c_int32 ) , <EOL> ( "<STR_LIT>" , c_char * MAXCOMLEN ) , <EOL> ] <EOL> def __str__ ( self ) : <EOL> return format_structure ( self ) <EOL> class DivertHandleRaw ( Structure ) : <EOL> """<STR_LIT>""" <EOL> _fields_ = [ <EOL> ( "<STR_LIT>" , c_uint32 ) , <EOL> ( "<STR_LIT>" , c_int ) , <EOL> ( "<STR_LIT>" , c_int ) , <EOL> ( "<STR_LIT>" , c_int ) , <EOL> ( "<STR_LIT>" , c_int ) , <EOL> ( "<STR_LIT>" , c_int * <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" , c_int * <NUM_LIT:2> ) , <EOL> ( "<STR_LIT>" , c_char_p ) , <EOL> ( "<STR_LIT>" , c_size_t ) , <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , c_size_t ) , <EOL> ( "<STR_LIT>" , c_uint64 ) , <EOL> ( "<STR_LIT>" , c_uint64 ) , <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , c_void_p ) , <EOL> ( "<STR_LIT>" , c_ubyte ) , <EOL> ( "<STR_LIT>" , c_char_p ) , <EOL> ( "<STR_LIT>" , c_char * Defaults . DIVERT_ERRBUF_SIZE ) <EOL> ] <EOL> def __str__ ( self ) : <EOL> return format_structure ( self ) </s>
