[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question on modifying packet header



Hi,

I am writing a new scheduling object which is under the Queue class.
Inside this scheduler, I am trying to modify a user flag of the packet header.
I did the following:
--------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "queue.h"
#include "packet.h"
#include "ip.h"
#include "flags.h"

class WFM : public Queue {
public: 
	WFM();
	virtual int command(int argc, const char*const* argv);
	Packet *deque(void);
	void enque(Packet *pkt);
	void recv(Packet* p, Handler* h);
protected:

	void whatever(Packet *pkt);
	int off_ip_;
	int off_flags_;

};

WFM::whatever(Packet *p)
{
	..... skip .....
	
		hdr_flags * hf = (hdr_flags *) p->access(off_flags_); 
		hf->usr1_++;
		
	..... skip .....	
}
----------------------------------------------------------------------

Unfortunately, it gives me a segmentation fault!
When I check with a debugger, i see hf is returned a strange address 0x470.
And certainly, it will crash when I try to use that address. Am I supposed to
have a hf value equals to an offset address starting from the one pointed by
p? Or , is it bacause a packet structure is not accessable by the Queue class?

Please advice.

Thanks in advance.

Keith.