Hi I am constructing an ICMP packet using C++ and want to convert sequence number into network byte order. I know we can use htons: here is my code:
struct ICMPheader
{
unsigned int seqence_no;
};
ICMPheader header;
header.sequence_no = htons (sequence_no++);
but it is giving error that sequence_no is not declared in this scope...
can anybody help with this ASAP..
Thanks,
It doesn't understand you want to use sequence_no from inside that structure, you have to tell it which structure to use like header.sequence_no
hi
sequence_no is the one of the parameter in the structure ..
i think you havent declared the sequence_no externally.
plz change the code as below
header.sequence_no = htons (header.sequence_no++);
if it is not working ... plz let me know
Also -
htons takes an unsigned short as its argument.
On 32 bit systems an int is 32 bits, a short is 16bits. try htonl()