INNER CODE UNIT · Python
main_loop
emanuele-f/PCAPdroid · tools/udp_receiver.py:71
def main_loop():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("0.0.0.0", args.port))
pcap_header_sent = False
# Send the individual records (struct pcaprec_hdr_s)
while True:
data, addr = sock.recvfrom(BUFSIZE)
is_pcap_header = (len(data) == PCAP_HEADER_SIZE) and (data.startswith(PCAP_HDR_BYTES_PREFIX))
if(args.verbose):
sys.stderr.write("Got a {}B packet\n".format(len(data)))
if(not pcap_header_sent) and (not is_pcap_header):
# This tool was started after PCAPdroid, so we must build a PCAP header
# Determine is the PCAPDroid trailer is in use