git.stg.codes
/
stg.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ed14477
)
Add name to anonymous union
author
Maxim Mamontov
<faust.madf@gmail.com>
Wed, 14 Sep 2011 15:21:56 +0000
(18:21 +0300)
committer
Maxim Mamontov
<faust.madf@gmail.com>
Wed, 14 Sep 2011 15:21:56 +0000
(18:21 +0300)
include/stg/raw_ip_packet.h
patch
|
blob
|
history
diff --git
a/include/stg/raw_ip_packet.h
b/include/stg/raw_ip_packet.h
index bf8bc577adb42646fd103747980e72f6379a2f6c..16e434025a9d76d9d77637b1995b4cf97f93dcea 100644
(file)
--- a/
include/stg/raw_ip_packet.h
+++ b/
include/stg/raw_ip_packet.h
@@
-20,15
+20,17
@@
enum { pcktSize = 68 }; //60(max) ip + 8 udp or tcp (part of tcp or udp header t
struct RAW_PACKET
{
RAW_PACKET()
struct RAW_PACKET
{
RAW_PACKET()
- : dataLen(-1)
+ : rawPacket(),
+ dataLen(-1)
{
{
- memset(pckt, 0, pcktSize);
+ memset(
rawPacket.
pckt, 0, pcktSize);
}
RAW_PACKET(const RAW_PACKET & rp)
}
RAW_PACKET(const RAW_PACKET & rp)
- : dataLen(rp.dataLen)
+ : rawPacket(),
+ dataLen(rp.dataLen)
{
{
- memcpy(
pckt, rp
.pckt, pcktSize);
+ memcpy(
rawPacket.pckt, rp.rawPacket
.pckt, pcktSize);
}
uint16_t GetIPVersion() const;
}
uint16_t GetIPVersion() const;
@@
-54,76
+56,76
@@
union
uint16_t sPort;
uint16_t dPort;
} header __attribute__ ((packed));
uint16_t sPort;
uint16_t dPort;
} header __attribute__ ((packed));
- };
+ }
rawPacket
;
int32_t dataLen; // IP packet length. Set to -1 to use length field from the header
};
//-----------------------------------------------------------------------------
inline uint16_t RAW_PACKET::GetIPVersion() const
{
int32_t dataLen; // IP packet length. Set to -1 to use length field from the header
};
//-----------------------------------------------------------------------------
inline uint16_t RAW_PACKET::GetIPVersion() const
{
-return header.ipHeader.ip_v;
+return
rawPacket.
header.ipHeader.ip_v;
}
//-----------------------------------------------------------------------------
inline uint8_t RAW_PACKET::GetHeaderLen() const
{
}
//-----------------------------------------------------------------------------
inline uint8_t RAW_PACKET::GetHeaderLen() const
{
-return header.ipHeader.ip_hl * 4;
+return
rawPacket.
header.ipHeader.ip_hl * 4;
}
//-----------------------------------------------------------------------------
inline uint8_t RAW_PACKET::GetProto() const
{
}
//-----------------------------------------------------------------------------
inline uint8_t RAW_PACKET::GetProto() const
{
-return header.ipHeader.ip_p;
+return
rawPacket.
header.ipHeader.ip_p;
}
//-----------------------------------------------------------------------------
inline uint32_t RAW_PACKET::GetLen() const
{
if (dataLen != -1)
return dataLen;
}
//-----------------------------------------------------------------------------
inline uint32_t RAW_PACKET::GetLen() const
{
if (dataLen != -1)
return dataLen;
-return ntohs(header.ipHeader.ip_len);
+return ntohs(
rawPacket.
header.ipHeader.ip_len);
}
//-----------------------------------------------------------------------------
inline uint32_t RAW_PACKET::GetSrcIP() const
{
}
//-----------------------------------------------------------------------------
inline uint32_t RAW_PACKET::GetSrcIP() const
{
-return header.ipHeader.ip_src.s_addr;
+return
rawPacket.
header.ipHeader.ip_src.s_addr;
}
//-----------------------------------------------------------------------------
inline uint32_t RAW_PACKET::GetDstIP() const
{
}
//-----------------------------------------------------------------------------
inline uint32_t RAW_PACKET::GetDstIP() const
{
-return header.ipHeader.ip_dst.s_addr;
+return
rawPacket.
header.ipHeader.ip_dst.s_addr;
}
//-----------------------------------------------------------------------------
inline uint16_t RAW_PACKET::GetSrcPort() const
{
}
//-----------------------------------------------------------------------------
inline uint16_t RAW_PACKET::GetSrcPort() const
{
-if (header.ipHeader.ip_p == 1) // for icmp proto return port 0
+if (
rawPacket.
header.ipHeader.ip_p == 1) // for icmp proto return port 0
return 0;
return 0;
-return ntohs(*((uint16_t*)(
pckt +
header.ipHeader.ip_hl * 4)));
+return ntohs(*((uint16_t*)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4)));
}
//-----------------------------------------------------------------------------
inline uint16_t RAW_PACKET::GetDstPort() const
{
}
//-----------------------------------------------------------------------------
inline uint16_t RAW_PACKET::GetDstPort() const
{
-if (header.ipHeader.ip_p == 1) // for icmp proto return port 0
+if (
rawPacket.
header.ipHeader.ip_p == 1) // for icmp proto return port 0
return 0;
return 0;
-return ntohs(*((uint16_t*)(
pckt +
header.ipHeader.ip_hl * 4 + 2)));
+return ntohs(*((uint16_t*)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4 + 2)));
}
//-----------------------------------------------------------------------------
inline bool RAW_PACKET::operator==(const RAW_PACKET & rvalue) const
{
}
//-----------------------------------------------------------------------------
inline bool RAW_PACKET::operator==(const RAW_PACKET & rvalue) const
{
-if (
header.ipHeader.ip_src.s_addr != rvalue
.header.ipHeader.ip_src.s_addr)
+if (
rawPacket.header.ipHeader.ip_src.s_addr != rvalue.rawPacket
.header.ipHeader.ip_src.s_addr)
return false;
return false;
-if (
header.ipHeader.ip_dst.s_addr != rvalue
.header.ipHeader.ip_dst.s_addr)
+if (
rawPacket.header.ipHeader.ip_dst.s_addr != rvalue.rawPacket
.header.ipHeader.ip_dst.s_addr)
return false;
return false;
-if (
header.ipHeader.ip_p != 1 && rvalue
.header.ipHeader.ip_p != 1)
+if (
rawPacket.header.ipHeader.ip_p != 1 && rvalue.rawPacket
.header.ipHeader.ip_p != 1)
{
{
- if (*((uint16_t *)(
pckt +
header.ipHeader.ip_hl * 4)) !=
- *((uint16_t *)(rvalue.
pckt + rvalue
.header.ipHeader.ip_hl * 4)))
+ if (*((uint16_t *)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4)) !=
+ *((uint16_t *)(rvalue.
rawPacket.pckt + rvalue.rawPacket
.header.ipHeader.ip_hl * 4)))
return false;
return false;
- if (*((uint16_t *)(
pckt +
header.ipHeader.ip_hl * 4 + 2)) !=
- *((uint16_t *)(rvalue.
pckt + rvalue
.header.ipHeader.ip_hl * 4 + 2)))
+ if (*((uint16_t *)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4 + 2)) !=
+ *((uint16_t *)(rvalue.
rawPacket.pckt + rvalue.rawPacket
.header.ipHeader.ip_hl * 4 + 2)))
return false;
}
return false;
}
-if (
header.ipHeader.ip_p != rvalue
.header.ipHeader.ip_p)
+if (
rawPacket.header.ipHeader.ip_p != rvalue.rawPacket
.header.ipHeader.ip_p)
return false;
return true;
return false;
return true;
@@
-131,34
+133,34
@@
return true;
//-----------------------------------------------------------------------------
inline bool RAW_PACKET::operator<(const RAW_PACKET & rvalue) const
{
//-----------------------------------------------------------------------------
inline bool RAW_PACKET::operator<(const RAW_PACKET & rvalue) const
{
-if (
header.ipHeader.ip_src.s_addr < rvalue
.header.ipHeader.ip_src.s_addr)
+if (
rawPacket.header.ipHeader.ip_src.s_addr < rvalue.rawPacket
.header.ipHeader.ip_src.s_addr)
return true;
return true;
-if (
header.ipHeader.ip_src.s_addr > rvalue
.header.ipHeader.ip_src.s_addr)
+if (
rawPacket.header.ipHeader.ip_src.s_addr > rvalue.rawPacket
.header.ipHeader.ip_src.s_addr)
return false;
return false;
-if (
header.ipHeader.ip_dst.s_addr < rvalue
.header.ipHeader.ip_dst.s_addr)
+if (
rawPacket.header.ipHeader.ip_dst.s_addr < rvalue.rawPacket
.header.ipHeader.ip_dst.s_addr)
return true;
return true;
-if (
header.ipHeader.ip_dst.s_addr > rvalue
.header.ipHeader.ip_dst.s_addr)
+if (
rawPacket.header.ipHeader.ip_dst.s_addr > rvalue.rawPacket
.header.ipHeader.ip_dst.s_addr)
return false;
return false;
-if (
header.ipHeader.ip_p != 1 && rvalue
.header.ipHeader.ip_p != 1)
+if (
rawPacket.header.ipHeader.ip_p != 1 && rvalue.rawPacket
.header.ipHeader.ip_p != 1)
{
{
- if (*((uint16_t *)(
pckt +
header.ipHeader.ip_hl * 4)) <
- *((uint16_t *)(rvalue.
pckt + rvalue
.header.ipHeader.ip_hl * 4)))
+ if (*((uint16_t *)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4)) <
+ *((uint16_t *)(rvalue.
rawPacket.pckt + rvalue.rawPacket
.header.ipHeader.ip_hl * 4)))
return true;
return true;
- if (*((uint16_t *)(
pckt +
header.ipHeader.ip_hl * 4)) >
- *((uint16_t *)(rvalue.
pckt + rvalue
.header.ipHeader.ip_hl * 4)))
+ if (*((uint16_t *)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4)) >
+ *((uint16_t *)(rvalue.
rawPacket.pckt + rvalue.rawPacket
.header.ipHeader.ip_hl * 4)))
return false;
return false;
- if (*((uint16_t *)(
pckt +
header.ipHeader.ip_hl * 4 + 2)) <
- *((uint16_t *)(rvalue.
pckt + rvalue
.header.ipHeader.ip_hl * 4 + 2)))
+ if (*((uint16_t *)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4 + 2)) <
+ *((uint16_t *)(rvalue.
rawPacket.pckt + rvalue.rawPacket
.header.ipHeader.ip_hl * 4 + 2)))
return true;
return true;
- if (*((uint16_t *)(
pckt +
header.ipHeader.ip_hl * 4 + 2)) >
- *((uint16_t *)(rvalue.
pckt + rvalue
.header.ipHeader.ip_hl * 4 + 2)))
+ if (*((uint16_t *)(
rawPacket.pckt + rawPacket.
header.ipHeader.ip_hl * 4 + 2)) >
+ *((uint16_t *)(rvalue.
rawPacket.pckt + rvalue.rawPacket
.header.ipHeader.ip_hl * 4 + 2)))
return false;
}
return false;
}
-if (
header.ipHeader.ip_p < rvalue
.header.ipHeader.ip_p)
+if (
rawPacket.header.ipHeader.ip_p < rvalue.rawPacket
.header.ipHeader.ip_p)
return true;
return false;
return true;
return false;