sockets - How to copy a char[] in c into my struct -


I am trying to send my straight onto a UDP socket.

struct packet {int seqnum; Four data [buffersize]; };

Therefore I have the sender

  bytes = size (packet); Send four [bytes]; Berzo (sending, bytes); Memcpy ((* Zero *), (Zero *) and Packet, Size (Bytes)); Bytes = Send (sockfd, send, size (sending), 0, (Structure Socadar *) and Client, Client Size);  

So I'm hoping that my [struct] makes a copy in four.

On my receiver

  int bytes; Bytes = size (structure packet); Four rick [bytes]; Bytes = Ricuffermum (Sokfad, RQV, Bytes, 0, (Structure Sokadar *) and Client, and Client Size); Memcpy ((* Zero *) currentpkt, (zero *) recv, bytes);  

However with memcpy ((* zero *) currentpkt, (zero *) recv, bytes) on the receiver; I get an error:

Error: Can not convert to an indicator type

What am I doing wrong? Is there a better way to send my straight onto the UDP socket?

***** UPDATE *****

Thanks everyone for the answers. Finally I '& amp; But my code looks like this now.

From:

  zero udt_send (struct packet packet) {int bytes; Bytes = Sending (Sokfad, (Four *) and Packet, Size (Packet), 0, (Structured soaked *) and Client, Client Size); }  

receiver:

  bytes = returnfram (sockfd, (four *) and current pkt, bytes, 0, (structure sockdom *) and client, And client size);  

It's good that in C, we put it in a four and send the bytes.

currentpkt is the type of structure; You need to get an indicator for the structure to work:

  memcpy (& currentpkt, recv, bytes);  

For your second question, do you have some other problems if you get more bytes in more packets than size (struct packet) ? As it is now written, you will lift your structure up.

What if client and server applications are compiled using different compilers or settings, or on different endless platforms? In this case, the Stret can have different sizes on two platforms and can be kept in separate memory.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -