473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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.
Nov 16 '05 #1
2 2050
"D.Frangiskatos" <fd**@gre.ac.uk> wrote in message
news:02****************************@phx.gbl...
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 http://msdn.microsoft.com 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.

Regards,
Will
Nov 16 '05 #2
"D. Frangiskatos" <fd**@gre.ac.uk> wrote in message
news:0a****************************@phx.gbl...
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
afterwards.


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

Regards,
Will

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: manders2k | last post by:
Hi all -- I'm contemplating the idea of writing a simple emacs-like editor in python (for fun and the experience of doing so). In reading through Craig Finseth's "The Craft of Text Editing": ...
1
by: Wim Deprez | last post by:
Hi group, I am trying to port a reliable multicast framework for UNIX to Win32 and so far so good, but I stumbled on the next problem: in the original code, the programmers use the recvmsg()...
1
by: inkapyrite | last post by:
Hi all. I'm using ifstream to read from a named pipe but i've encountered an annoying problem. For some reason, the program blocks on reading an ifstream's internal buffer that's only half-filled....
2
by: William | last post by:
I have declared the following struct: struct PropagateInfo { string type; // "registration", "gossip", "termination" int initiatePeerID; }; which I used as follows: PropagateInfo*...
9
by: Omega | last post by:
I have a problem with recvfrom(). I get a message and no error occurs, but the struct sockaddr* from is not filled with sender's data. The client's source code: #include "reversi.h"...
16
by: junky_fellow | last post by:
Is there any efficcient way of removing the newline character from the buffer read by fgets() ? Is there any library function that is similar to fgets() but also tells how many bytes it read...
1
by: Jack | last post by:
Hi guys, I can't figure this out. rec = recvfrom(sdUDP, buf, BUFSIZE, 0, (struct sockaddr *)&connectChannel, &chanSizeUDP ); while(1){ if (rec 0){ snt = sendto(sdUDP, buf, rec, 0, (struct...
5
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME thing, these are just 2 different names for the...
3
by: jkvbe | last post by:
Hi, I get a "Bad address" error message when trying to receive an ICMP timestamp packet using recvfrom in cygwin. The packet is OK as I see it arriving when sniffing the network. Any ideas...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.