[英]Why doesn't my program work with different Linux distros?
我正在研究數據包嗅探器。 最大的問題是我的代碼只能在Backtrack 5 R3下完美運行,但它在其他發行版下不起作用! 事實上,在Ubuntu 12.10和ArchLinux上,當嗅探器獲得第一個數據包時,我遇到了分段錯誤(我得到“分段故障核心轉儲”)。 起初,我認為錯誤在於庫或編譯器,但經過一些測試后,我想我可以排除它們! 情況就是這樣:
所以我嘗試將Arch降級為gcc 4.4.3 e libpcap 1.0.0,但我得到了同樣的錯誤。 編譯代碼時我有一些警告,但沒有什么真正重要的,但它在回溯下運行完美! 這是個大謎。
這是導致問題的代碼:
void packet_dump(unsigned char *arguments, const struct pcap_pkthdr *pcap_data, const unsigned char *packet) {
int packet_data_len, tcp_header_size=0, total_header_size;
unsigned char *packet_data;
const unsigned char *ip_src_dest;
const struct header_ip *ip_header;
//Calculate the value of variables
ip_src_dest = (packet+LUNGHEZZA_INTESTAZIONE_ETH);
ip_header = (const struct header_ip *)ip_src_dest;
total_header_size = LUNGHEZZA_INTESTAZIONE_ETH+sizeof(struct header_ip)+tcp_header_size;
packet_data = (unsigned char *)packet + total_header_size;
packet_data_len = pcap_data->len - total_header_size;
//THIS CAUSE THE PROBLEM (Solved removing inet_ntoa and converting it manually)
printf("[ %s ] ============> ", inet_ntoa(ip_header->source_addr_ip));
printf("[ %s ] \n", inet_ntoa(ip_header->destination_addr_ip));
}
我懷疑你的程序崩潰了,因為ip_header-> source_addr_ip指向你不允許訪問的內存。 您應該能夠使用GDB來確定是否是這種情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.