title: capture packets for a specific app on Android
body: <p>I want to capture the network packets for a specific app on Android (4.1 or later) emulator. Since I do not know which ports the target app will open, tcpdump, wireshark may not be able to do this. iptables can make log for specific UID, while each downloaded app will associated with a unique UID during run time. However, it seems iptables cannot only log some header information of the packets.
  I am now thinking of using iptables to block all traffic except for the target app, and then use tcpdump to capture the packets, but the iptable on my emulator seems do not work. Someone said I need to compile and build my emulator from the source code and enable the netfilter/iptables. Does anyone know how to do this? Or is there any available emulator image I can use?
  If there is a better way to capture the packets for a targeted app, that would be better.</p>