Skip to content Skip to sidebar Skip to footer

How To Get Uid From Packet - Android

I am developing a firewall application in android where I need to identify apps based on uid. I have created a vpn service and I am able to capture packets and get destination ip

Solution 1:

Parse the packet, for TCP/UDP, you can retrieve the (local_ip, local_port, remote_ip, remote_port) tuple. Then read and parse /proc/net/tcp or /proc/net/udp, there's uid field in it.

This is a loopback socket whose owner uid is 10117:

sllocal_addressrem_addresssttx_queuerx_queuetrtm->when retrnsmt   uid  timeout inode
7: 0100007F:8FC5 0100007F:04380100000000:0000000000:00000000000000001011702426071000000002142610 -1

Solution 2:

You will have to write some native code for this to communicate at kernel level.

Post a Comment for "How To Get Uid From Packet - Android"