8 #include <netinet/in.h> // for htons
10 enum { pcktSizeOLD = 68 }; //60(max) ip + 8 udp or tcp (part of tcp or udp header to ports)
11 //-----------------------------------------------------------------------------
17 memset(pckt, 0, pcktSizeOLD);
20 RawPacketOld(const RawPacketOld& rp)
23 memcpy(pckt, rp.pckt, pcktSizeOLD);
26 uint16_t GetIPVersion() const
30 uint8_t GetHeaderLen() const
32 return (pckt[0] & 0x0F) * 4;
34 uint8_t GetProto() const
38 uint32_t GetLen() const
42 return ntohs(*reinterpret_cast<const uint16_t*>(pckt + 2));
44 uint32_t GetSrcIP() const
46 return *reinterpret_cast<const uint32_t*>(pckt + 12);
48 uint32_t GetDstIP() const
50 return *reinterpret_cast<const uint32_t*>(pckt + 16);
52 uint16_t GetSrcPort() const
54 if (GetProto() == 1) // for icmp proto return port 0
56 return ntohs(*reinterpret_cast<const uint16_t*>(pckt + GetHeaderLen()));
58 uint16_t GetDstPort() const
60 if (GetProto() == 1) // for icmp proto return port 0
62 return ntohs(*reinterpret_cast<const uint16_t*>(pckt + GetHeaderLen() + 2));
65 uint8_t pckt[pcktSizeOLD]; // îÁÞÁÌÏ ÐÁËÅÔÁ ÚÁÈ×ÁÞÅÎÎÏÇÏ ÉÚ ÓÅÔÉ
66 int32_t dataLen; // äÌÉÎÁ IP ÐÁËÅÔÁ. åÓÌÉ -1, ÔÏ ÉÓÐÏÌØÚÏ×ÁÔØ ÄÌÉÎÕ ÉÚ ÚÁÇÏÌÏ×ËÁ ÓÁÍÏÇÏ ÐÁËÅÔÁ.
68 //-----------------------------------------------------------------------------
69 inline bool operator==(const RawPacketOld& lhs, const RawPacketOld& rhs)
71 if (lhs.GetSrcIP() != rhs.GetSrcIP())
74 if (lhs.GetDstIP() != rhs.GetDstIP())
77 if (lhs.GetSrcPort() != rhs.GetSrcPort())
80 if (lhs.GetDstPort() != rhs.GetDstPort())
83 if (lhs.GetProto() != rhs.GetProto())
88 //-----------------------------------------------------------------------------
89 inline bool operator<(const RawPacketOld& lhs, const RawPacketOld& rhs)
91 if (lhs.GetSrcIP() < rhs.GetSrcIP())
93 if (lhs.GetSrcIP() > rhs.GetSrcIP())
96 if (lhs.GetDstIP() < rhs.GetDstIP())
98 if (lhs.GetDstIP() > rhs.GetDstIP())
101 if (lhs.GetSrcPort() < rhs.GetSrcPort())
103 if (lhs.GetSrcPort() > rhs.GetSrcPort())
106 if (lhs.GetDstPort() < rhs.GetDstPort())
108 if (lhs.GetDstPort() > rhs.GetDstPort())
111 if (lhs.GetProto() < rhs.GetProto())
117 if (lhs.GetProto() > rhs.GetProto())