導航:首頁 > 源碼編譯 > 網路聯機編譯時出現問題

網路聯機編譯時出現問題

發布時間:2023-07-05 15:58:55

① 如何解決編譯時出現的fatal error C1004: unexpected end of file found問題

編譯的時候要加條件知道嗎 -lpcap
*(mac_string+2),*(mac_string+3)' 這行的符號。有兩處。

別的錯誤 就沒發現了。
還有就是你可以再linux下編輯一下看看 錯誤到底是什麼。它都有提示的。我現在在windows下看得

現在這個代碼我在linux下調試通過了

#include <pcap.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
struct ether_header
{
u_int8_t ether_dhost[6];
u_int8_t ether_shost[6];
u_int16_t ether_type;

};
void ethernet_protocol_packet_callback(u_char*argument_wentaoliu,const struct
pcap_pkthdr*packet_header,const u_char*packet_content)
{
u_short ethernet_type;
struct ether_header*ethernet_protocol;
u_char*mac_string;
static int packet_number=1;
printf("--------------------------------------\n");
printf("捕獲第 %d個乙太網數據包\n",packet_number);
printf("數據包長度:\n");
printf("%d\n",packet_header->len);
printf("---------乙太網協議---------\n");
ethernet_protocol=(struct ether_header*)packet_content;
printf("乙太網類型:\n");
ethernet_type=ntohs(ethernet_protocol->ether_type);
printf("%04x\n",ethernet_type);
switch(ethernet_type)
{
case 0x0800: printf("上層協議為IP協議\n");break;
case 0x0806: printf("上層協議為ARP協議\n");break;
case 0x8035: printf("上層協議為RARP協議\n");break;
default :break;
}
printf("源乙太網地址:\n");
mac_string=ethernet_protocol->ether_shost;
printf("%02x:%02x:%02x:%02x:%02x:%02x\n",*mac_string,*(mac_string+1),
*(mac_string+2),*(mac_string+3),
*(mac_string+4),*(mac_string+5));
printf("目的太網地址:\n");
mac_string=ethernet_protocol->ether_dhost;
printf("%02x:%02x:%02x:%02x:%02x:%02x\n",*mac_string,*(mac_string+1),
*(mac_string+2),*(mac_string+3),
*(mac_string+4),*(mac_string+5));
printf("--------------------------------------\n");
packet_number++;
}
int main(void)
{
pcap_t*pcap_handle;
char error_content[PCAP_ERRBUF_SIZE];
char*net_interface;
struct bpf_program bpf_filter;
char bpf_filter_string[]="ip";
bpf_u_int32 net_mask;
bpf_u_int32 net_ip;
net_interface= pcap_lookupdev(error_content);
pcap_lookupnet(net_interface,&net_ip,&net_mask,error_content);
pcap_handle= pcap_open_live(net_interface,BUFSIZ,1,1,error_content);
pcap_compile(pcap_handle,&bpf_filter,bpf_filter_string,0,net_ip);
pcap_setfilter(pcap_handle,&bpf_filter);
if(pcap_datalink(pcap_handle)!=DLT_EN10MB)
return 0;
pcap_loop(pcap_handle,-1,ethernet_protocol_packet_callback,NULL);
pcap_close(pcap_handle);
return 0;
}

閱讀全文

與網路聯機編譯時出現問題相關的資料

熱點內容
java實現快捷鍵 瀏覽:94
程序員打代碼最佳時間 瀏覽:569
怎麼裝原生態安卓 瀏覽:847
工程圖學pdf 瀏覽:398
開放的程序員 瀏覽:952
胡希恕傷寒論講座pdf 瀏覽:766
aspnet程序員薪水 瀏覽:76
蘋果為什麼屏幕看得比安卓舒服 瀏覽:119
蘋果數據線怎麼轉安卓 瀏覽:656
黑格爾pdf下載 瀏覽:959
備忘錄里新建文件夾怎麼刪除 瀏覽:12
伺服器黑名單怎麼處理 瀏覽:842
程序員電視劇25集 瀏覽:214
80351單片機 瀏覽:958
advancedwifi源碼 瀏覽:577
maczip解壓成文件夾後怎麼打開 瀏覽:120
androidapp內存大小 瀏覽:451
程序員干私活網站 瀏覽:379
未來軟體加密鎖驅動 瀏覽:930
美軍如何拒絕執行上級命令 瀏覽:489