A
aki
Hi all,
i am writing codes for implementing network protocols.
i have written a method which is receiving a packet from network.
i have assumed that the packet i will receive will be of type char*.
i need to test my method and
for that i want to create a network buffer which will contain a
packet of format as->
example of Configuration req packet
uint8_t code;
uint8_t identifier;
uint16_t length;
option1
option2
.....
option n
for eg option1 can be.... AuthProtocol with fields as
uint8_t type;
uint8_t length;
uint16_t authpro;
i was tryin to do like this.. but it has a limitation....
supposing packet contains header and only one option..
it will need 8 byte aas a whole..
char *buffer=new char(8);// allocating buffer with required memory
memset(buffer,1,1); // setting code field as 1
memset(buffer+1,4,1); // setting identifier as 4
memset(buffer+2,25,2); // here i am not able to put length in 2 byte
field as memset works with only one byte ...
filling option1 now...
memset(buffer+4,3,1);
memset(buffer+5,4,1);
memset(buffer+6,23,2);
i am not getting any other way to do it....
All comments are most welcome...
Thanks and Regards
Aki
i am writing codes for implementing network protocols.
i have written a method which is receiving a packet from network.
i have assumed that the packet i will receive will be of type char*.
i need to test my method and
for that i want to create a network buffer which will contain a
packet of format as->
example of Configuration req packet
uint8_t code;
uint8_t identifier;
uint16_t length;
option1
option2
.....
option n
for eg option1 can be.... AuthProtocol with fields as
uint8_t type;
uint8_t length;
uint16_t authpro;
i was tryin to do like this.. but it has a limitation....
supposing packet contains header and only one option..
it will need 8 byte aas a whole..
char *buffer=new char(8);// allocating buffer with required memory
memset(buffer,1,1); // setting code field as 1
memset(buffer+1,4,1); // setting identifier as 4
memset(buffer+2,25,2); // here i am not able to put length in 2 byte
field as memset works with only one byte ...
filling option1 now...
memset(buffer+4,3,1);
memset(buffer+5,4,1);
memset(buffer+6,23,2);
i am not getting any other way to do it....
All comments are most welcome...
Thanks and Regards
Aki