summaryrefslogtreecommitdiff
path: root/src/base/inet.hh
diff options
context:
space:
mode:
authorAli Saidi <saidi@eecs.umich.edu>2009-01-06 10:36:56 -0500
committerAli Saidi <saidi@eecs.umich.edu>2009-01-06 10:36:56 -0500
commit11ac0c7acfe2d75d51e56e3a4305bf3209b3d420 (patch)
treee71f4c1768ac58d0e3366aa22efd9e26c3bd14eb /src/base/inet.hh
parent9f89d43b653061fe335cdb4c8dfac9b046d6416c (diff)
downloadgem5-11ac0c7acfe2d75d51e56e3a4305bf3209b3d420.tar.xz
INET: Add functions to header types to get offset in packet and start of payload; add function to split packet at last known header
Diffstat (limited to 'src/base/inet.hh')
-rw-r--r--src/base/inet.hh42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/base/inet.hh b/src/base/inet.hh
index 21ac5c89e..59b05291d 100644
--- a/src/base/inet.hh
+++ b/src/base/inet.hh
@@ -140,6 +140,8 @@ class EthPtr
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return 0; }
+ int pstart() const { return off() + ((const EthHdr*)p->data)->size(); }
};
/*
@@ -216,6 +218,8 @@ class IpPtr
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return sizeof(eth_hdr); }
+ int pstart() const { return off() + get()->size(); }
};
uint16_t cksum(const IpPtr &ptr);
@@ -279,9 +283,9 @@ class TcpPtr
{
protected:
EthPacketPtr p;
- int off;
+ int _off;
- void set(const EthPacketPtr &ptr, int offset) { p = ptr; off = offset; }
+ void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
void set(const IpPtr &ptr)
{
if (ptr && ptr->proto() == IP_PROTO_TCP)
@@ -291,25 +295,27 @@ class TcpPtr
}
public:
- TcpPtr() : p(0), off(0) {}
- TcpPtr(const IpPtr &ptr) : p(0), off(0) { set(ptr); }
- TcpPtr(const TcpPtr &ptr) : p(ptr.p), off(ptr.off) {}
+ TcpPtr() : p(0), _off(0) {}
+ TcpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
+ TcpPtr(const TcpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
- TcpHdr *get() { return (TcpHdr *)(p->data + off); }
+ TcpHdr *get() { return (TcpHdr *)(p->data + _off); }
TcpHdr *operator->() { return get(); }
TcpHdr &operator*() { return *get(); }
- const TcpHdr *get() const { return (const TcpHdr *)(p->data + off); }
+ const TcpHdr *get() const { return (const TcpHdr *)(p->data + _off); }
const TcpHdr *operator->() const { return get(); }
const TcpHdr &operator*() const { return *get(); }
const TcpPtr &operator=(const IpPtr &i) { set(i); return *this; }
- const TcpPtr &operator=(const TcpPtr &t) { set(t.p, t.off); return *this; }
+ const TcpPtr &operator=(const TcpPtr &t) { set(t.p, t._off); return *this; }
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return _off; }
+ int pstart() const { return off() + get()->size(); }
};
uint16_t cksum(const TcpPtr &ptr);
@@ -366,9 +372,9 @@ class UdpPtr
{
protected:
EthPacketPtr p;
- int off;
+ int _off;
- void set(const EthPacketPtr &ptr, int offset) { p = ptr; off = offset; }
+ void set(const EthPacketPtr &ptr, int offset) { p = ptr; _off = offset; }
void set(const IpPtr &ptr)
{
if (ptr && ptr->proto() == IP_PROTO_UDP)
@@ -378,29 +384,33 @@ class UdpPtr
}
public:
- UdpPtr() : p(0), off(0) {}
- UdpPtr(const IpPtr &ptr) : p(0), off(0) { set(ptr); }
- UdpPtr(const UdpPtr &ptr) : p(ptr.p), off(ptr.off) {}
+ UdpPtr() : p(0), _off(0) {}
+ UdpPtr(const IpPtr &ptr) : p(0), _off(0) { set(ptr); }
+ UdpPtr(const UdpPtr &ptr) : p(ptr.p), _off(ptr._off) {}
- UdpHdr *get() { return (UdpHdr *)(p->data + off); }
+ UdpHdr *get() { return (UdpHdr *)(p->data + _off); }
UdpHdr *operator->() { return get(); }
UdpHdr &operator*() { return *get(); }
- const UdpHdr *get() const { return (const UdpHdr *)(p->data + off); }
+ const UdpHdr *get() const { return (const UdpHdr *)(p->data + _off); }
const UdpHdr *operator->() const { return get(); }
const UdpHdr &operator*() const { return *get(); }
const UdpPtr &operator=(const IpPtr &i) { set(i); return *this; }
- const UdpPtr &operator=(const UdpPtr &t) { set(t.p, t.off); return *this; }
+ const UdpPtr &operator=(const UdpPtr &t) { set(t.p, t._off); return *this; }
const EthPacketPtr packet() const { return p; }
EthPacketPtr packet() { return p; }
bool operator!() const { return !p; }
operator bool() const { return p; }
+ int off() const { return _off; }
+ int pstart() const { return off() + get()->size(); }
};
uint16_t cksum(const UdpPtr &ptr);
+int hsplit(const EthPacketPtr &ptr);
+
/* namespace Net */ }
#endif // __BASE_INET_HH__