<s> from __future__ import print_function <EOL> from bcc import BPF <EOL> import argparse <EOL> examples = """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( <EOL> description = "<STR_LIT>" , <EOL> formatter_class = argparse . RawDescriptionHelpFormatter , <EOL> epilog = examples ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> debug = <NUM_LIT:0> <EOL> bpf_text = """<STR_LIT>""" <EOL> if args . pid : <EOL> bpf_text = bpf_text . replace ( '<STR_LIT>' , <EOL> '<STR_LIT>' % args . pid ) <EOL> else : <EOL> bpf_text = bpf_text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if debug : <EOL> print ( bpf_text ) <EOL> b = BPF ( text = bpf_text ) <EOL> b . attach_kprobe ( event = "<STR_LIT>" , fn_name = "<STR_LIT>" ) <EOL> b . attach_kprobe ( event = "<STR_LIT>" , fn_name = "<STR_LIT>" ) <EOL> b . attach_kretprobe ( event = "<STR_LIT>" , fn_name = "<STR_LIT>" ) <EOL> b . attach_kretprobe ( event = "<STR_LIT>" , fn_name = "<STR_LIT>" ) <EOL> if args . timestamp : <EOL> print ( "<STR_LIT>" % ( "<STR_LIT>" ) , end = "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> start_ts = <NUM_LIT:0> <EOL> def inet_ntoa ( addr ) : <EOL> dq = '<STR_LIT>' <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:4> ) : <EOL> dq = dq + str ( addr & <NUM_LIT> ) <EOL> if ( i != <NUM_LIT:3> ) : <EOL> dq = dq + '<STR_LIT:.>' <EOL> addr = addr >> <NUM_LIT:8> <EOL> return dq <EOL> while <NUM_LIT:1> : <EOL> ( task , pid , cpu , flags , ts , msg ) = b . trace_fields ( ) <EOL> ( ip_s , saddr_hs , daddr_hs , dport_s ) = msg . split ( "<STR_LIT:U+0020>" ) <EOL> if args . timestamp : <EOL> if start_ts == <NUM_LIT:0> : <EOL> start_ts = ts <EOL> print ( "<STR_LIT>" % ( ts - start_ts ) , end = "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % ( pid , task , ip_s , <EOL> inet_ntoa ( int ( saddr_hs , <NUM_LIT:16> ) ) if ip_s == "<STR_LIT:4>" else "<STR_LIT>" + saddr_hs , <EOL> inet_ntoa ( int ( daddr_hs , <NUM_LIT:16> ) ) if ip_s == "<STR_LIT:4>" else "<STR_LIT>" + daddr_hs , <EOL> dport_s ) ) </s>
