1
我想解析包括不同类型的网络包(有些被标记为VLAN,有些不是)使用#包括一个pcap文件。 这里是我到目前为止的代码:如何使用libpcap和C获取VLAN标签?
pcap_t *pcap;
const unsigned char *packet;
char errbuf[PCAP_ERRBUF_SIZE];
struct pcap_pkthdr header;
pcap = pcap_open_offline(argv[0], errbuf);
if (pcap == NULL)
{
fprintf(stderr, "error reading pcap file: %s\n", errbuf);
exit(1);
}
while ((packet = pcap_next(pcap, &header)) != NULL)
{
struct ip_header *ip;
unsigned int IP_header_length;
packet += sizeof(struct ether_header);
capture_len -= sizeof(struct ether_header);
ip = (struct ip_header*) packet;
IP_header_length = ip->vhl * 4; /* ip_hl is in 4-byte words */
char *sinfo = strdup(inet_ntoa(ip->src));
char *dinfo = strdup(inet_ntoa(ip->dst));
printf ("%s<-__->%s\n", sinfo ,dinfo);
free (sinfo);
free (dinfo);
}
必须有某处代码来检查VLAN和跃过他们correctly.How我应该区分非虚拟局域网VLAN的报文?
谢谢您的格式正确的问题,不过,我不确定如果你问“如何以最佳方式组织该代码”还是你问“我怎么取使用'libpcap''的VLAN标记,如果是的话,你是针对802.1q&ISL吗? –
非常感谢。我已经改变了这个问题。是的,我真正想看的只是IP头。 – mazkopolo