summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2004-09-21 01:41:55 -0400
committerNathan Binkert <binkertn@umich.edu>2004-09-21 01:41:55 -0400
commit1d02345a24f6e439545c0752e4dfcb54b8a23537 (patch)
tree04a19bc6a9e3d96b776a499b716ac15234b193d6 /dev
parenta58b834c8e333385f9be37eb4d343d70f8177613 (diff)
downloadgem5-1d02345a24f6e439545c0752e4dfcb54b8a23537.tar.xz
a bit more cleaning of the network header wrappers.
base/inet.hh: add functions to the various headers to grab the most common encapsulated protocols. This could easily get out of hand, but we're just worrying about tcp, udp, and ip for now. add common functions size(), bytes(), and payload() to all wrappers. size() gets the header size bytes() returns a uint8_t * to the beginning of the header payload() returns a uint8_t * to the beginning of the payload. dev/etherpkt.cc: dev/etherpkt.hh: don't cache pointers to headers. It's probably not worth the hassle. --HG-- extra : convert_revision : ba9df85ac019b8a48233042dde79fb9da9546410
Diffstat (limited to 'dev')
-rw-r--r--dev/etherpkt.cc23
-rw-r--r--dev/etherpkt.hh30
2 files changed, 11 insertions, 42 deletions
diff --git a/dev/etherpkt.cc b/dev/etherpkt.cc
index 292fe7faf..273b8ee64 100644
--- a/dev/etherpkt.cc
+++ b/dev/etherpkt.cc
@@ -34,29 +34,6 @@
using namespace std;
void
-PacketData::doext()
-{
- _eth = 0;
- _ip = 0;
- _tcp = 0;
- _udp = 0;
-
- if (!data)
- return;
-
- _eth = data;
- if (eth()->type() == ETH_TYPE_IP) {
- _ip = eth()->payload();
-
- if (ip()->proto() == IP_PROTO_TCP)
- _tcp = ip()->payload();
-
- if (ip()->proto() == IP_PROTO_UDP)
- _udp = ip()->payload();
- }
-}
-
-void
PacketData::serialize(ostream &os)
{
SERIALIZE_SCALAR(length);
diff --git a/dev/etherpkt.hh b/dev/etherpkt.hh
index 53612b830..9c5f00491 100644
--- a/dev/etherpkt.hh
+++ b/dev/etherpkt.hh
@@ -51,30 +51,22 @@ class PacketData : public RefCounted
uint8_t *data;
int length;
- protected:
- uint8_t *_eth;
- uint8_t *_ip;
- uint8_t *_tcp;
- uint8_t *_udp;
-
- void doext();
- void ext()
- {
- if (_eth != data)
- doext();
- }
-
public:
- PacketData() : data(NULL), length(0) { doext(); }
+ PacketData() : data(NULL), length(0) { }
PacketData(std::auto_ptr<uint8_t> d, int l)
- : data(d.release()), length(l) { doext(); }
+ : data(d.release()), length(l) { }
~PacketData() { if (data) delete [] data; }
public:
- EthHdr *eth() { ext(); return (EthHdr *)_eth; }
- IpHdr *ip() { ext(); return (IpHdr *)_ip; }
- TcpHdr *tcp() { ext(); return (TcpHdr *)_tcp; }
- UdpHdr *udp() { ext(); return (UdpHdr *)_udp; }
+ const EthHdr *eth() const { return (const EthHdr *)data; }
+ const IpHdr *ip() const {const EthHdr *h = eth(); return h ? h->ip() : 0;}
+ const TcpHdr *tcp() const {const IpHdr *h = ip(); return h ? h->tcp() : 0;}
+ const UdpHdr *udp() const {const IpHdr *h = ip(); return h ? h->udp() : 0;}
+
+ EthHdr *eth() { return (EthHdr *)data; }
+ IpHdr *ip() { EthHdr *h = eth(); return h ? h->ip() : 0; }
+ TcpHdr *tcp() { IpHdr *h = ip(); return h ? h->tcp() : 0; }
+ UdpHdr *udp() { IpHdr *h = ip(); return h ? h->udp() : 0; }
public:
void serialize(std::ostream &os);