Android使用tcpdump抓包

AllJoyn中有个问题:Server切换到Client后,重新加入其他Server时join session会失败,原因是timeout(join session是异步的,在指定时间内没有收到回应)。

之前TV和手机连接时也有这种问题,后来发现是LinkTimeout被设置为0了,将其改为40就ok了。

 

但现在time out值已经是40了还报这种问题就头疼了。怎么办?

权衡一下,我决定先抓包确认join session时数据包到底发送出去没有。

 

在linux下这是一件很简单的事,tcpdump就可以搞定。但Android下还得费点心思(手机和我们的工作pc不在一个网络中,因此无法在pc上给Android抓包)。

 

好在这种事很多人都做过,很容易找到他们的经验。

1. 手机要有root权限

2. 下载tcpdump   http://www.strazzere.com/android/tcpdump

3. adb push c:\wherever_you_put\tcpdump /data/local/tcpdump

4. adb shell chmod 6755 /data/local/tcpdump

5, adb shell,   su获得root权限

6, cd /data/local

7, ./tcpdump -i any -p -s 0 -w /sdcard/capture.pcap

命令参数:

 

        # "-i any": listen on any network interface

  # "-p": disable promiscuous mode (doesn't work anyway)

  # "-s 0": capture the entire packet

  # "-w": write packets to a file (rather than printing to stdout)

  ... do whatever you want to capture, then ^C to stop it ...

 

8,  adb pull /sdcard/capture.pcap d:/

9,  在电脑上用wireshark打开capture.pcap即可分析log

http://www.cnblogs.com/likwo/archive/2012/09/06/2673944.html

 

 

 

posted @ 2013-09-06 14:45    阅读(436)  评论(0编辑  收藏  举报