1 #ifndef RAW_IP_PACKET_OLD_H
2 #define RAW_IP_PACKET_OLD_H
4 #include <netinet/in.h> // for htons
5 //#include <netinet/ip.h> // for struct ip
13 enum { pcktSizeOLD = 68 }; //60(max) ip + 8 udp or tcp (part of tcp or udp header to ports)
14 //-----------------------------------------------------------------------------
20 memset(pckt, 0, pcktSizeOLD);
23 RAW_PACKET_OLD(const RAW_PACKET_OLD & rp)
26 memcpy(pckt, rp.pckt, pcktSizeOLD);
29 uint16_t GetIPVersion() const;
30 uint8_t GetHeaderLen() const;
31 uint8_t GetProto() const;
32 uint32_t GetLen() const;
33 uint32_t GetSrcIP() const;
34 uint32_t GetDstIP() const;
35 uint16_t GetSrcPort() const;
36 uint16_t GetDstPort() const;
38 uint8_t pckt[pcktSizeOLD]; // îÁÞÁÌÏ ÐÁËÅÔÁ ÚÁÈ×ÁÞÅÎÎÏÇÏ ÉÚ ÓÅÔÉ
39 int32_t dataLen; // äÌÉÎÁ IP ÐÁËÅÔÁ. åÓÌÉ -1, ÔÏ ÉÓÐÏÌØÚÏ×ÁÔØ ÄÌÉÎÕ ÉÚ ÚÁÇÏÌÏ×ËÁ ÓÁÍÏÇÏ ÐÁËÅÔÁ.
41 //-----------------------------------------------------------------------------
42 inline uint16_t RAW_PACKET_OLD::GetIPVersion() const
46 //-----------------------------------------------------------------------------
47 inline uint8_t RAW_PACKET_OLD::GetHeaderLen() const
49 return (pckt[0] & 0x0F) * 4;
51 //-----------------------------------------------------------------------------
52 inline uint8_t RAW_PACKET_OLD::GetProto() const
56 //-----------------------------------------------------------------------------
57 inline uint32_t RAW_PACKET_OLD::GetLen() const
61 return ntohs(*(uint16_t*)(pckt + 2));
63 //-----------------------------------------------------------------------------
64 inline uint32_t RAW_PACKET_OLD::GetSrcIP() const
66 return *(uint32_t*)(pckt + 12);
68 //-----------------------------------------------------------------------------
69 inline uint32_t RAW_PACKET_OLD::GetDstIP() const
71 return *(uint32_t*)(pckt + 16);
73 //-----------------------------------------------------------------------------
74 inline uint16_t RAW_PACKET_OLD::GetSrcPort() const
76 if (GetProto() == 1) // for icmp proto return port 0
78 return ntohs(*((uint16_t*)(pckt + GetHeaderLen())));
80 //-----------------------------------------------------------------------------
81 inline uint16_t RAW_PACKET_OLD::GetDstPort() const
83 if (GetProto() == 1) // for icmp proto return port 0
85 return ntohs(*((uint16_t*)(pckt + GetHeaderLen() + 2)));
87 //-----------------------------------------------------------------------------
88 inline bool operator==(const RAW_PACKET_OLD & lhs, const RAW_PACKET_OLD & rhs)
90 if (lhs.GetSrcIP() != rhs.GetSrcIP())
93 if (lhs.GetDstIP() != rhs.GetDstIP())
96 if (lhs.GetSrcPort() != rhs.GetSrcPort())
99 if (lhs.GetDstPort() != rhs.GetDstPort())
102 if (lhs.GetProto() != rhs.GetProto())
107 //-----------------------------------------------------------------------------
108 inline bool operator<(const RAW_PACKET_OLD & lhs, const RAW_PACKET_OLD & rhs)
110 if (lhs.GetSrcIP() < rhs.GetSrcIP())
112 if (lhs.GetSrcIP() > rhs.GetSrcIP())
115 if (lhs.GetDstIP() < rhs.GetDstIP())
117 if (lhs.GetDstIP() > rhs.GetDstIP())
120 if (lhs.GetSrcPort() < rhs.GetSrcPort())
122 if (lhs.GetSrcPort() > rhs.GetSrcPort())
125 if (lhs.GetDstPort() < rhs.GetDstPort())
127 if (lhs.GetDstPort() > rhs.GetDstPort())
130 if (lhs.GetProto() < rhs.GetProto())
136 if (lhs.GetProto() > rhs.GetProto())
144 //-----------------------------------------------------------------------------