solved warnings for gcc-4 (breaking of strict-aliasing rules)
parent
725d630672
commit
ec67dc43a2
|
@ -104,8 +104,8 @@ class QuintupleKey
|
|||
uint32_t ip1, ip2;
|
||||
uint16_t port1, port2;
|
||||
if (p->ipProtocolType == Packet::TCP) {
|
||||
ip1 = *((uint32_t*)(p->data.netHeader + 12));
|
||||
ip2 = *((uint32_t*)(p->data.netHeader + 16));
|
||||
memcpy(&ip1, p->data.netHeader + 12, sizeof(ip1));
|
||||
memcpy(&ip2, p->data.netHeader + 16, sizeof(ip2));
|
||||
port1 = *((uint16_t*)(p->transportHeader));
|
||||
port2 = *((uint16_t*)(p->transportHeader + 2));
|
||||
|
||||
|
|
|
@ -32,11 +32,13 @@ void PacketIDMEFReporter::analyzePacket(Packet* p, IDMEFMessage* msg)
|
|||
{
|
||||
char buffer[20];
|
||||
uint16_t i = PacketHashtable::getRawPacketFieldOffset(IeInfo(IPFIX_TYPEID_sourceIPv4Address, 0), p);
|
||||
uint32_t srcip = *(uint32_t*)(p->data.netHeader+i);
|
||||
uint32_t srcip;
|
||||
memcpy(&srcip, p->data.netHeader+i, sizeof(srcip));
|
||||
msg->setVariable(PAR_SRCIP, IPToString(srcip).c_str());
|
||||
msg->setVariable(IDMEFMessage::PAR_SOURCE_ADDRESS, IPToString(srcip).c_str());
|
||||
i = PacketHashtable::getRawPacketFieldOffset(IeInfo(IPFIX_TYPEID_destinationIPv4Address, 0), p);
|
||||
uint32_t dstip = *(uint32_t*)(p->data.netHeader+i);
|
||||
uint32_t dstip;
|
||||
memcpy(&dstip, p->data.netHeader+i, sizeof(dstip));
|
||||
msg->setVariable(PAR_DSTIP, IPToString(dstip).c_str());
|
||||
msg->setVariable(IDMEFMessage::PAR_TARGET_ADDRESS, IPToString(dstip).c_str());
|
||||
i = PacketHashtable::getRawPacketFieldOffset(IeInfo(IPFIX_TYPEID_protocolIdentifier, 0), p);
|
||||
|
@ -44,16 +46,19 @@ void PacketIDMEFReporter::analyzePacket(Packet* p, IDMEFMessage* msg)
|
|||
snprintf(buffer, 20, "%hhu", protocol);
|
||||
msg->setVariable(PAR_PROTOCOL, buffer);
|
||||
i = PacketHashtable::getRawPacketFieldOffset(IeInfo(IPFIX_TYPEID_octetDeltaCount, 0), p);
|
||||
uint16_t packetlen = *(uint16_t*)(p->data.netHeader+i);
|
||||
uint16_t packetlen;
|
||||
memcpy(&packetlen, p->data.netHeader+i, sizeof(packetlen));
|
||||
snprintf(buffer, 20, "%hu", packetlen);
|
||||
msg->setVariable(PAR_LENGTH, buffer);
|
||||
if ((protocol & (Packet::TCP|Packet::UDP))>0) {
|
||||
i = PacketHashtable::getRawPacketFieldOffset(IeInfo(IPFIX_TYPEID_sourceIPv4Address, 0), p);
|
||||
uint16_t srcport = *(uint16_t*)(p->data.netHeader+i);
|
||||
uint16_t srcport;
|
||||
memcpy(&srcport, p->data.netHeader+i, sizeof(srcport));
|
||||
snprintf(buffer, 20, "%hu", srcport);
|
||||
msg->setVariable(PAR_SRCPORT, srcport);
|
||||
i = PacketHashtable::getRawPacketFieldOffset(IeInfo(IPFIX_TYPEID_sourceTransportPort, 0), p);
|
||||
uint16_t dstport = *(uint16_t*)(p->data.netHeader+i);
|
||||
uint16_t dstport;
|
||||
memcpy(&dstport, p->data.netHeader+i, sizeof(dstport));
|
||||
snprintf(buffer, 20, "%hu", dstport);
|
||||
msg->setVariable(PAR_DSTPORT, buffer);
|
||||
}
|
||||
|
|
|
@ -138,7 +138,9 @@ void PacketHashtable::copyDataTransportOctets(CopyFuncParameters* cfp)
|
|||
switch (cfp->packet->ipProtocolType) {
|
||||
case Packet::TCP:
|
||||
ppd = reinterpret_cast<PayloadPrivateData*>(cfp->dst+cfp->efd->privDataOffset);
|
||||
ppd->seq = ntohl(*reinterpret_cast<const uint32_t*>(p->data.netHeader+p->transportHeaderOffset+4))+plen+(p->data.netHeader[p->transportHeaderOffset+13] & 0x02 ? 1 : 0);
|
||||
uint32_t hu32_data;
|
||||
memcpy(&hu32_data, p->data.netHeader+p->transportHeaderOffset+4, sizeof(uint32_t));
|
||||
ppd->seq = hu32_data+plen+(p->data.netHeader[p->transportHeaderOffset+13] & 0x02 ? 1 : 0);
|
||||
ppd->initialized = true;
|
||||
break;
|
||||
|
||||
|
@ -200,8 +202,11 @@ void PacketHashtable::aggregateFrontPayload(IpfixRecord::Data* bucket, Hashtable
|
|||
|
||||
IpfixRecord::Data* dst = bucket+efd->dstIndex;
|
||||
uint32_t seq = 0;
|
||||
if (src->ipProtocolType==Packet::TCP)
|
||||
seq = ntohl(*reinterpret_cast<const uint32_t*>(src->data.netHeader+src->transportHeaderOffset+4));
|
||||
if (src->ipProtocolType==Packet::TCP) {
|
||||
uint32_t hu32_data;
|
||||
memcpy(&hu32_data, src->data.netHeader+src->transportHeaderOffset+4, sizeof(uint32_t));
|
||||
seq = hu32_data;
|
||||
}
|
||||
DPRINTFL(MSG_VDEBUG, "seq:%u, len:%u, udp:%u", seq, ppd->byteCount, src->ipProtocolType==Packet::UDP);
|
||||
|
||||
if (firstpacket || !ppd->initialized) {
|
||||
|
@ -1089,10 +1094,14 @@ void PacketHashtable::aggregateField(const ExpFieldData* efd, HashtableBucket* h
|
|||
switch (p->ipProtocolType) {
|
||||
case Packet::TCP:
|
||||
ppd = reinterpret_cast<PayloadPrivateData*>(data+efd->privDataOffset);
|
||||
seq = ntohl(*reinterpret_cast<const uint32_t*>(p->data.netHeader+p->transportHeaderOffset+4));
|
||||
uint32_t hu32_data;
|
||||
memcpy(&hu32_data, p->data.netHeader+p->transportHeaderOffset+4, sizeof(uint32_t));
|
||||
seq = hu32_data;
|
||||
|
||||
if (!ppd->initialized) {
|
||||
ppd->seq = ntohl(*reinterpret_cast<const uint32_t*>(p->data.netHeader+p->transportHeaderOffset+4))+plen+(p->data.netHeader[p->transportHeaderOffset+13] & 0x02 ? 1 : 0);
|
||||
uint32_t hu32_data;
|
||||
memcpy(&hu32_data, p->data.netHeader+p->transportHeaderOffset+4, sizeof(uint32_t));
|
||||
ppd->seq = hu32_data+plen+(p->data.netHeader[p->transportHeaderOffset+13] & 0x02 ? 1 : 0);
|
||||
|
||||
*reinterpret_cast<uint64_t*>(baseData) = htonll(plen);
|
||||
ppd->initialized = true;
|
||||
|
|
|
@ -40,10 +40,12 @@ bool HostFilter::processPacket(Packet *p)
|
|||
return false;
|
||||
}
|
||||
// srcIP
|
||||
uint32_t srcIp = *reinterpret_cast<uint32_t*>(p->data.netHeader+IPV4_SRC_IP_OFFSET);
|
||||
uint32_t srcIp;
|
||||
memcpy(&srcIp, p->data.netHeader+IPV4_SRC_IP_OFFSET, sizeof(srcIp));
|
||||
msg(MSG_DIALOG, "srcip: %X, %s", srcIp, IPToString(srcIp).c_str());
|
||||
// dstIP
|
||||
uint32_t dstIp = *reinterpret_cast<uint32_t*>(p->data.netHeader+IPV4_DST_IP_OFFSET);
|
||||
uint32_t dstIp;
|
||||
memcpy(&dstIp, p->data.netHeader+IPV4_DST_IP_OFFSET, sizeof(dstIp));
|
||||
|
||||
if (addrFilter == "src") {
|
||||
return (ipList.find(srcIp) != ipList.end());
|
||||
|
|
Loading…
Reference in New Issue