title: C sending structure over udp socket
body: <p>I have implemented udp server and client in C. Server (64-bit PC) is  sending udp packets which contain sequence numbers of the packets to the client (also 64-bit PC). Sequence number is unsigned long int type. Server correctly reads this sequence number and sends the packet over the socket. The problem is at the client side,it reads correctly all packets until he reaches 65 535 packet, then he starts from 0. It makes no sense because also at the client side sequence number of the packetis unsigned long int type. Below are also my function for encoding at the server side at decoding at the client side, maybe you can see mistake? Thx</p>
  
  <p>server encoding</p>
  
  <pre><code>size_t encode(packet pack, char buf[MAX_SIZE]){
  
  
      size_t pack_len;
      unsigned char *pt = buf;
  
      *pt++ = (pack.tos &gt;&gt; 8) &amp; 255;
      *pt++ = (pack.tos &amp; 255);
  
      *pt++ = (pack.seq_num  &gt;&gt; 24) &amp; 255 ;
      *pt++ = (pack.seq_num  &gt;&gt; 16)&amp; 255;
      *pt++ = (pack.seq_num &gt;&gt; 8) &amp; 255;
      *pt++ = (pack.seq_num &amp; 255);
  
      strcpy(pt,pack.buffer);
      pt += strlen(pack.buffer)+1;
      pack_len = sizeof(pack.tos) +sizeof(pack.seq_num) + strlen(pack.buffer); 
  
      return pack_len;
  
  }
  </code></pre>
  
  <p>client decoding</p>
  
  <pre><code>packet decode(char *buf) {
  
      packet pack;
      unsigned char *pt = buf;
  
      pack.tos = *pt++ &lt;&lt; 8;
      pack.tos += *pt++;
  
      pack.seq_num = *pt++ &lt;&lt; 24;
      pack.seq_num = *pt++ &lt;&lt; 16;
      pack.seq_num = *pt++ &lt;&lt; 8;
      pack.seq_num += *pt++;
  
      strcpy(pack.buffer, pt);
      return pack;
  }
  </code></pre>