title: How can I handle an incoming packet connection by parsing the buffer and placing the data into the correct struct?
body: <p>I have an open connection that works fine, but now I'm adding a second reply type that I have to handle.  The replies go to two different structs.</p>
  
  <p>Reply type one is a struct of size 16 = replyTypeOne (int, int, int, int)
  Reply type two is a struct of size 64 = replyTypeTwo (int, int, int, char[48], int)</p>
  
  <p>Before I was sending the reply straight to the correct struct - now I have to add a buffer to determine which struct the reply should go to.</p>
  
  <p>old handle of code below:</p>
  
  <pre><code>iResult = recv(connectSocket, (char *)&amp;replyTypeOne, sizeof(replyTypeOne), 0);
  </code></pre>
  
  <p>The above code would place the reply fields into their appropiate places.  However, with the replyTypeTwo being different than replyTypeOne - I need a solution to determine the two replies from each other.</p>
  
  <p>So I plan on using a buffer (maybe I should use MSG_PEEK??), to look at the incoming data and place it into the correct struct.  I'm just not sure how to handle / parse the buffer reply atm.</p>
  
  <p>EDIT:
  added replyTemp struct -  int, int, int, int, char[48], int</p>
  
  <pre><code>#define DEFAULT_BUFLEN 128
  
  int iResult;
  char recvbuf[DEFAULT_BUFLEN];
  int recvbuflen = DEFAULT_BUFLEN;
  
  iResult = recv(connectSocket, (char *)&amp;replyTemp, sizeof(replyTemp), 0)
  
  if(iResult &gt; 0)
  {
   if(replyTemp.length &gt; 16)
    {
     //handle replyTypeTwo -  assign replyTypeTwo fields to replyTemp fields
    } else {
     // handle replyTypeOne - asking replyTypeOne fields to replyTemp fields
    }
  }
  else if(iResult == 0)
  {
    connectSocket = INVALID_SOCKET;
  }
  </code></pre>