Manipulating packets data within a network

Hi everybody!

I am a newbie in cpp and I am trying to make some changes in a simulator through storing incoming packets in a buffer adding 6 bytes to them (according to an identity matrix) then forward then enque them in a queue.
The enque function is already existing and the accessdata function is defined as follow:

class Packet : public Event {
private:
friend class PacketQueue;
u_char* bits_;
u_char* data_; /* variable size buffer for 'data' /
u_int datalen_; /* length of variable size buffer /
protected:
static Packet* free_;
public:
...
inline u_char* accessdata() { return data_; }
};


Here is a part of my code

while (p != 0) {

count++;

switch (count){

case 1:
buffer[6]= *p->accessdata();
buffer[0]='1';
buffer[1]='0';
buffer[2]='0';
buffer[3]='0';
buffer[4]='0';
buffer[5]='0';
case 2:
buffer[6]= *p->accessdata();
buffer[0]='0';
buffer[1]='1';
buffer[2]='0';
buffer[3]='0';
buffer[4]='0';
buffer[5]='0';
case 3:
buffer[6]= *p->accessdata();
buffer[0]='0';
buffer[1]='0';
buffer[2]='1';
buffer[3]='0';
buffer[4]='0';
buffer[5]='0';
case 4:
buffer[6]= *p->accessdata();
buffer[0]='0';
buffer[1]='0';
buffer[2]='0';
buffer[3]='1';
buffer[4]='0';
buffer[5]='0';
case 5:
buffer[6]= *p->accessdata();
buffer[0]='0';
buffer[1]='0';
buffer[2]='0';
buffer[3]='0';
buffer[4]='1';
buffer[5]='0';
case 6:
buffer[6]= *p->accessdata();
buffer[0]='0';
buffer[1]='0';
buffer[2]='0';
buffer[3]='0';
buffer[4]='0';
buffer[5]='1';
default:
count=0;
}

p->accessdata()= buffer;



q_->enque(p);

....
/************************/

I am just wondering if my impelentation ist technically right and/ or if there is a better way to do the same thing!

Thank you in advance,

Dan.

Topic archived. No new replies allowed.