diff --git a/src/scan.c b/src/scan.c index 9a67731..fa3ec2a 100644 --- a/src/scan.c +++ b/src/scan.c @@ -19,33 +19,22 @@ static void dispatch_callback(u_char *user, const struct pcap_pkthdr *h, const struct scan *data = (struct scan *)user; const struct iphdr *iphdr = (struct iphdr *)(bytes + sizeof(struct ether_header)); + const void *packet = bytes + sizeof(struct ether_header) + sizeof(struct iphdr); if (iphdr->protocol == IPPROTO_TCP && h->caplen >= sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct tcphdr)) { - tcp_response( - (const struct tcphdr *)(bytes + - sizeof(struct ether_header) + - sizeof(struct iphdr)), - data); + tcp_response(packet, data); } if (iphdr->protocol == IPPROTO_UDP && h->caplen >= sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct udphdr)) { - udp_response( - (const struct udphdr *)(bytes + - sizeof(struct ether_header) + - sizeof(struct iphdr)), - data); + udp_response(packet, data); } if (iphdr->protocol == IPPROTO_ICMP && h->caplen >= sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct icmphdr)) { - icmp_response( - (const struct icmphdr *)(bytes + - sizeof(struct ether_header) + - sizeof(struct iphdr)), - data); + icmp_response(packet, data); } }