1. Android的netstat
netstat代码如下所示:
- int netstat_main(int argc, char *argv[])
- {
- printf("Proto Recv-Q Send-Q Local Address Foreign Address State\n");
- ipv4("/proc/net/tcp", "tcp");
- ipv4("/proc/net/udp", "udp");
- ipv6("/proc/net/tcp6", "tcp6");
- ipv6("/proc/net/udp6", "udp6");
- return 0;
- }
如:cat /proc/net/tcp6内容如下:
# cat /proc/net/tcp6
sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt
uid timeout inode
0: 00000000000000000000000000000000:EA60 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 10031 0 8220 1 eded9b80 300 0 0 2 -1
1: 00000000000000000000000000000000:1873 00000000000000000000000000000000:0000 0A 00000000:00000000 00:00000000 00000000 10071 0 8214 1 eded8000 300 0 0 2 -1
2: 0000000000000000FFFF00008204A8C0:E066 0000000000000000FFFF0000CEEB7D4A:0050 08 00000000:00000001 00:00000000 00000000 1000 0 5015 1 eded8b00 21 4 22 10 -1
3: 0000000000000000FFFF00008204A8C0:EA60 0000000000000000FFFF00005B04A8C0:CECD 01 00000000:00000000 00:00000000 00000000 10031 0 8376 1 ededa100 300 0 0 10 -1
如对于端口EA60 (60000)的uid为10031,大于10000的uid为app。
2. 在pid中如何寻找对应的uid
如我的10031在app_31中。
app_31 2761 1378 454512 28132 ffffffff 400e7ae8 S cn.mytest.test
# cat /proc/2761/cgroup
2:cpu:/bg_non_interactive
1:cpuacct:/uid/10031
其实很简单,app_xx对应的uid为10000+xx
(myarrow) |