import struct,sys
for path in sys.argv[1:]:
    try: f=open(path,'rb')
    except Exception as e: print(path,e); continue
    gh=f.read(24)
    if len(gh)<24: print(path,'EMPTY'); continue
    end={b'\xd4\xc3\xb2\xa1':'<',b'\xa1\xb2\xc3\xd4':'>',b'\x4d\x3c\xb2\xa1':'<',b'\xa1\xb2\x3c\x4d':'>'}[gh[:4]]
    print('===',path)
    n=0
    while True:
        ph=f.read(16)
        if len(ph)<16: break
        ts,_,incl,_=struct.unpack(end+'IIII',ph); d=f.read(incl)
        if len(d)<incl: break
        et=struct.unpack('>H',d[12:14])[0]; o=14
        if et==0x8100: et=struct.unpack('>H',d[16:18])[0]; o=18
        if et!=0x0800: continue
        ihl=(d[o]&0xf)*4
        if d[o+9]!=17: continue
        t=o+ihl
        if len(d)<t+8: continue
        sp,dp,ul,cs=struct.unpack('>HHHH',d[t:t+8])
        pay=d[t+8:t+ul]
        if dp!=443 and sp!=443: continue
        if len(pay)<40: continue
        n+=1
        if n>3: break
        print('  len=%d' % len(pay))
        print('   %s' % pay[:64].hex())
    if n==0: print('  (no udp payloads)')
