我的iOS的初學者,我的畢業設計是建立一種應用程序,可以在iOS上捕獲數據包。libpcap的iOS上的pcap_next()總是返回null
我使用libpcap的圖書館。我的iPhone是JB,我已經可以以root身份運行的應用程序。更具體地說,我可以得到我的net_interface:en0,但我無法捕獲任何數據包。pcap_next()總是返回null。
這是我的代碼:
-(IBAction)capture:(id)sender{
char error_content[PCAP_ERRBUF_SIZE];
char *net_interface=NULL;
net_interface=pcap_lookupdev(error_content);
NSString *devstr = [[NSString alloc] initWithUTF8String:net_interface];
text1.text=devstr;
pcap_t *pcap_handle;
pcap_handle = pcap_open_live(net_interface, BUFSIZ, 0, 2, error_content);
struct pcap_pkthdr packet_capture;
const u_char *packet_flag;
packet_flag= pcap_next(pcap_handle, &packet_capture);
if (!packet_flag) {
[email protected]"capture failed";
}
else{
NSString *length =[[NSString alloc]initWithFormat:@"the length of packet is %d",packet_capture.len];
text2.text=length;
[length release];
}
pcap_close(pcap_handle);
}
@end
如果有人對此有類似的記錄或不知道如何解決這個問題,我會更感激,如果你可以通過[email protected]與我聯繫。
它解決了。我用它代替pcap_next.It工作,不錯的pcap_loop。 – 2013-04-26 08:06:15