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