这个例子和上个例子一样,功能是捕获数据包,并分析其属于IP, ARP, RARP还是其他。与上个例子不同的是这个例子中采用pcap_loop()作为捕包函数,同时调用回调函数pcap_packet_call_back()对数据包进行分析。
/********************************************************************************
* file name : get_ethernet2_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;
};
/* call back fuction*********************/
void ethernet_protocol_packet_callback( u_char *argument, const struct pcap_pkthdr *packet_header, const u_char* packet_content)
{
u_short ethernet_type;
struct ether_he