Skip to content

Commit

Permalink
Added fix for VLAN Ethernet as proposed here: jvinet#89. Fixed log ou…
Browse files Browse the repository at this point in the history
…tput.
  • Loading branch information
TDFKAOlli committed Apr 4, 2024
1 parent f3e7e7d commit 735379d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/knockd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ void generate_pcap_filter()
cleanup(1);
}
strcpy(door->pcap_filter_exp, buffer);
dprint("Adding pcap expression for door '%s': %s\n", door->name, door->pcap_filter_exp);
dprint("Adding ipv6 pcap expression for door '%s': %s\n", door->name, door->pcap_filter_exp);
}
buffer[0] = '\0'; /* "clear" the buffer */
}
Expand Down Expand Up @@ -1631,12 +1631,17 @@ void sniff(u_char* arg, const struct pcap_pkthdr* hdr, const u_char* packet)

if(lltype == DLT_EN10MB) {
eth = (struct ether_header*)packet;
if(ntohs(eth->ether_type) != ETHERTYPE_IP && ntohs(eth->ether_type) != ETHERTYPE_IPV6) {
if(ntohs(eth->ether_type) != ETHERTYPE_IP && ntohs(eth->ether_type) != ETHERTYPE_IPV6 && ntohs(eth->ether_type) != ETHERTYPE_VLAN) {
return;
}

ip = (struct ip*)(packet + sizeof(struct ether_header));
ip6 = (struct ip6_hdr*)(packet + sizeof(struct ether_header));
int tag_size = 0;
if (ntohs(eth->ether_type) == ETHERTYPE_VLAN) {
tag_size = 4;
}

ip = (struct ip*)(packet + sizeof(struct ether_header) + tag_size);
ip6 = (struct ip6_hdr*)(packet + sizeof(struct ether_header) + tag_size);
#ifdef __linux__
} else if(lltype == DLT_LINUX_SLL) {
ip = (struct ip*)((u_char*)packet + 16);
Expand Down

0 comments on commit 735379d

Please sign in to comment.