diff --git a/examples/pcapscan.cc b/examples/pcapscan.cc index 92db5cdf..3ad20b1a 100644 --- a/examples/pcapscan.cc +++ b/examples/pcapscan.cc @@ -106,7 +106,8 @@ struct FiveTuple { dstAddr = iphdr->ip_dst.s_addr; // UDP/TCP ports - const struct udphdr *uh = reinterpret_cast(iphdr) + (iphdr->ip_hl * 4); + const char * iphdr_base = reinterpret_cast(iphdr); + const struct udphdr *uh = reinterpret_cast(iphdr_base + (iphdr->ip_hl * 4)); srcPort = uh->uh_sport; dstPort = uh->uh_dport; } @@ -231,7 +232,7 @@ public: } // Valid TCP or UDP packet - const struct ip *iphdr = reinterpret_cast(pktData) + sizeof(struct ether_header); + const struct ip *iphdr = reinterpret_cast(pktData + sizeof(struct ether_header)); const char *payload = reinterpret_cast(pktData) + offset; size_t id = stream_map.insert(std::make_pair(FiveTuple(iphdr), @@ -572,7 +573,8 @@ int main(int argc, char **argv) { */ static bool payloadOffset(const unsigned char *pkt_data, unsigned int *offset, unsigned int *length) { - const ip *iph = reinterpret_cast(pkt_data) + sizeof(ether_header); + const ip *iph = reinterpret_cast(pkt_data + sizeof(ether_header)); + const char *iph_base = reinterpret_cast(iph); const tcphdr *th = nullptr; // Ignore packets that aren't IPv4 @@ -591,7 +593,7 @@ static bool payloadOffset(const unsigned char *pkt_data, unsigned int *offset, switch (iph->ip_p) { case IPPROTO_TCP: - th = reinterpret_cast(iph) + ihlen; + th = reinterpret_cast(iph_base + ihlen); thlen = th->th_off * 4; break; case IPPROTO_UDP: