dstAddr = iphdr->ip_dst.s_addr;
// UDP/TCP ports
- const struct udphdr *uh = reinterpret_cast<const struct udphdr *>(iphdr) + (iphdr->ip_hl * 4);
+ const char * iphdr_base = reinterpret_cast<const char *>(iphdr);
+ const struct udphdr *uh = reinterpret_cast<const struct udphdr *>(iphdr_base + (iphdr->ip_hl * 4));
srcPort = uh->uh_sport;
dstPort = uh->uh_dport;
}
}
// Valid TCP or UDP packet
- const struct ip *iphdr = reinterpret_cast<const struct ip *>(pktData) + sizeof(struct ether_header);
+ const struct ip *iphdr = reinterpret_cast<const struct ip *>(pktData + sizeof(struct ether_header));
const char *payload = reinterpret_cast<const char *>(pktData) + offset;
size_t id = stream_map.insert(std::make_pair(FiveTuple(iphdr),
*/
static bool payloadOffset(const unsigned char *pkt_data, unsigned int *offset,
unsigned int *length) {
- const ip *iph = reinterpret_cast<const ip *>(pkt_data) + sizeof(ether_header);
+ const ip *iph = reinterpret_cast<const ip *>(pkt_data + sizeof(ether_header));
+ const char *iph_base = reinterpret_cast<const char *>(iph);
const tcphdr *th = nullptr;
// Ignore packets that aren't IPv4
switch (iph->ip_p) {
case IPPROTO_TCP:
- th = reinterpret_cast<const tcphdr *>(iph) + ihlen;
+ th = reinterpret_cast<const tcphdr *>(iph_base + ihlen);
thlen = th->th_off * 4;
break;
case IPPROTO_UDP: