By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,728 Members | 753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,728 IT Pros & Developers. It's quick & easy.

recvfrom buffer, VC Net sees only the first character, any ideas????

P: n/a
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:

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.


/*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!


ps: any Winsock programmers there who think that this code
sucks, probably you are right, and your advices-
corrections would be highly appreciated.
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
"D.Frangiskatos" <fd**> wrote in message
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.

The display in the watch window is according to the type of the variable
being watched. You delared a pointer to a character, so the IDE shows the
pointer and what it references. You can override that behavior when you
want. Search the MSDN-CD or at for the topic
"Symbols for Watch Variables".

Also note that if you view the memory window and insert an address there the
IDE will simple dump the memory locations as bytes, words, or longs.

Nov 16 '05 #2

P: n/a
"D. Frangiskatos" <fd**> wrote in message
Thanks for the tip,
You are welcome.
i have just tried it but it only shows it in a line, not a
collapsable tree kind structure like when we look at an
array :(
Even the IDE is "type safe". :-) Arrays and pointers are not the same thing
even though some of us long time C hacks think of them as the same. So
arrays are displayed in one way and pointers in another.

Just by the way, the watch window allows one to enter expressions as well as
casts. So, if you just want the twentieth byte for example you can enter
RecvNuffer[20] and it will show you a single byte. In addition, if you
choose Debug->Windows->Memory with 7.x or View->Debug Windows->Memory with
6.0 you will get both a binary and ASCII dump. A right click can be used to
specify that the "array" be seen as bytes, words or double words.
And another thing: i know it is logical that the IDE shows
the pointer and what it references but shouldn't be doing
that before the recvfrom is executed? Before the recvfrom
is executed you can place the mouse pointer on the
RecvBuffer and you can see its full length. But not

I'm not sure what you are seeing, but an intervening null byte (0) in the
array will likely end the display.


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.