本实例只捕获一个以太网的数据包,并分析其属于IP,ARP,RARP,还是其他。。。。。
其中使用pcap_next ( pcap_t *p, struct pcap_pkthdr *h)作为捕包函数。
/********************************************************
* filename : get_ethernet1_code.c *
* writer : starshift *
* ******************************************************/
#include <pcap.h>
struct ether_header
{
u_int8_t ether_dhost[6];
u_int8_t ether_shost[6];
u_int16_t ether_type;
};
void main()
{
char error_content[PCAP_ERRBUF_SIZE];
pcap_t *pcap_handle;
const u_char *packet_content;
u_char *mac_string;
u_short ethernet_type;
bpf_u_int32 net_mask;
bpf_u_int32 net_ip;
char *net_interface;
struct pcap_pkthdr protocol_header;
&nbs

该博客展示了如何使用pcap库捕获以太网数据包,并分析其类型,如IP、ARP或RARP。通过定义`ether_header`结构体,程序读取数据包并打印相关信息,包括源MAC地址、网络层协议和数据包长度。
最低0.47元/天 解锁文章
595

被折叠的 条评论
为什么被折叠?



