magic could happen on recvfrom
Ok, this is so weird that i can't even think why this could happen:
So I am trying to send a struct, which is a frame over UPD using the sendto, here's the code of my sender that shows where it sends and I am not given the code of the receiver, but I am asked to create one based on the binary executable that is given
Code:
/*Here's my struct*/
typedef struct FrameHdr {
u_char type;
SeqNum seq;
u_char size;
u_char flags;
} FrameHdr;
typedef struct Frame {
FrameHdr hdr;
u_char body[256];
} Frame;
/*Here's a snippet of my code*/
Frame* frame = (Frame*) calloc(1, sizeof(Frame));
fread(frame->body, 1 , 256, stdin);
frame->hdr.type = TYPE_DATA;
frame->hdr.seq = (SeqNum) LFS;
sendto(sock_fd,(void*)frame ,sizeof(Frame),0,(struct sockaddr *)&sockin, sizeof(sockin));
I'll provide more code if necessary. But here's where the weird thing started to happen. When I typed in from the stdin the following string and press enter:
Tom Sawyer is a nice, playful boy, a natural showoff who likes to show his authority over other boys. He is around twelve years old as gathered from hints in Twain's works. Tom is supposed to represent the carefree and wonderful world of boyhood in the early-mid 1800s.
clearly this sentence is more than 256 bytes, so I believe the sendto won't be able to send all the words. I think the sentence will be cut to (i.e: this is what I get when printing frame->body after the fread):
Tom Sawyer is a nice, playful boy, a natural showoff who likes to show his authority over other boys. He is around twelve years old as gathered from hints in Twain's works. Tom is supposed to represent the carefree and wonderful world of boyhood in the ear
However, here's the magical thing. When the receiver receives and prints this frame body I sent (the incomplete one), it could print the full sentence that I input in stdin although what I sent was not the complete one, the one I sent was missing the "ly-mid 1800s". Any idea how this could happen? Oh and yes I am pretty sure I only called sendto once..
I can't find out as I don't know what the source code for the binary looks, the binary is already provided.