导航:首页 > 源码编译 > 网络联机编译时出现问题

网络联机编译时出现问题

发布时间: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;
}

阅读全文

与网络联机编译时出现问题相关的资料

热点内容
程序员的甜品制作方法 浏览:200
找几本关于程序员职场的小说 浏览:356
拼多多app这是怎么回事 浏览:811
程序员那么可爱小说作者 浏览:204
pdf文件打不开怎么办 浏览:607
数字化校园系统源码 浏览:194
androidxml虚线 浏览:861
小学生催眠按摩解压视频 浏览:417
报修管理系统源码 浏览:76
java打印调用栈 浏览:792
网页加密视频怎么下载 浏览:555
程序员上班了可以学什么有用 浏览:564
程序员的谋生手段 浏览:431
泉州电视台直播源码 浏览:682
路径规划算法比较 浏览:87
墨刀开发APP如何设置背景图片 浏览:139
软件设计师教程pdf 浏览:726
python数据同时给多个线程 浏览:150
php内核源码入口 浏览:911
java内存图片 浏览:227