D
D.Frangiskatos
Hi,
I have been working for a few months in project that deals
raw sockets. However recently, and while trying to examine
the contents of the buffer used in recvfrom i was a bit
confused. The buffer was allocated using malloc as it can
be seen next:
do
{
..............
char *RecvBuffer = (char *) malloc(MAX_PACKET_SIZE);
..............
BytesRecv = recvfrom(Sock, (char*)RecvBuffer,
MAX_PACKET_SIZE+sizeof(IPV4_PACKET_HEADER), 0, (sockaddr *)
&incoming, &FromLen);
.................
process_the_packet(RecvBuffer, BytesRecv)
.................
}while (BytesRecv > 0);
When i added a watch on the RecvBuffer and tried to
examine it in debug mode i could only see the first
character on the incoming packet. I am not expert in C++
but the way i see it is that i have allocated in memory a
variable RecvBuffer that points to a char, with a size
MAX_PACKET_SIZE. Before the recvfrom is executed when you
put the mouse pointer on the RecvBuffer it looks as if you
were looking at a declared array (is as long as it is
supposed to be).
After the recvfrom is executed, if you examine the
RecvBuffer it shows that it only contains the first
character of the received packet (E because E=0x45, which
is 4 for the version of an IP header and 5 for its length).
So in order to examine the contents of the packet i had to
use the following lines. Probably there is a better way to
do this (and any ideas - examples would be highly
appreciated!!) but i needed a quick fix.
char rcv2[MAX_PACKET_SIZE+sizeof(IPV4_PACKET_HEADER)];
/*copy/store the received packet byte by byte*/
memcpy(rcv2,RecvBuffer, BytesRecv);
So any ideas why in debug i can't just see the contents of
the RecvBuffer and i have to use the above 2 lines of
code? It looks irrational to me that after the recvfrom is
executed VC++ shows only the first character of the
received packet. But again as i said before i am not an
expert in C++ so people be gentle with me!
Cheers
ps: any Winsock programmers there who think that this code
sucks, probably you are right, and your advices-
corrections would be highly appreciated.
I have been working for a few months in project that deals
raw sockets. However recently, and while trying to examine
the contents of the buffer used in recvfrom i was a bit
confused. The buffer was allocated using malloc as it can
be seen next:
do
{
..............
char *RecvBuffer = (char *) malloc(MAX_PACKET_SIZE);
..............
BytesRecv = recvfrom(Sock, (char*)RecvBuffer,
MAX_PACKET_SIZE+sizeof(IPV4_PACKET_HEADER), 0, (sockaddr *)
&incoming, &FromLen);
.................
process_the_packet(RecvBuffer, BytesRecv)
.................
}while (BytesRecv > 0);
When i added a watch on the RecvBuffer and tried to
examine it in debug mode i could only see the first
character on the incoming packet. I am not expert in C++
but the way i see it is that i have allocated in memory a
variable RecvBuffer that points to a char, with a size
MAX_PACKET_SIZE. Before the recvfrom is executed when you
put the mouse pointer on the RecvBuffer it looks as if you
were looking at a declared array (is as long as it is
supposed to be).
After the recvfrom is executed, if you examine the
RecvBuffer it shows that it only contains the first
character of the received packet (E because E=0x45, which
is 4 for the version of an IP header and 5 for its length).
So in order to examine the contents of the packet i had to
use the following lines. Probably there is a better way to
do this (and any ideas - examples would be highly
appreciated!!) but i needed a quick fix.
char rcv2[MAX_PACKET_SIZE+sizeof(IPV4_PACKET_HEADER)];
/*copy/store the received packet byte by byte*/
memcpy(rcv2,RecvBuffer, BytesRecv);
So any ideas why in debug i can't just see the contents of
the RecvBuffer and i have to use the above 2 lines of
code? It looks irrational to me that after the recvfrom is
executed VC++ shows only the first character of the
received packet. But again as i said before i am not an
expert in C++ so people be gentle with me!
Cheers
ps: any Winsock programmers there who think that this code
sucks, probably you are right, and your advices-
corrections would be highly appreciated.