title: Byte order with a large array of characters in C
body: <p>I am doing some socket programming in C, and trying to wrestle with byte order problems. My request (send) is fine but when I receive data my bytes are all out of order. I start with something like this:</p>
  <pre><code>char * aResponse= (char *)malloc(512);
  int total = recv(sock, aResponse, 511, 0);
  </code></pre>
  <p>When dealing with this response, each 16bit word seems to have it's bytes reversed (I'm using UDP). I tried to fix that by doing something like this:</p>
  <pre><code>    unsigned short * _netOrder= (unsigned short *)aResponse;
      unsigned short * newhostOrder= (unsigned short *)malloc(total);
      for (i = 0; i &lt; total; ++i)
      {
           newhostOrder[i] = ntohs(_netOrder[i]);
      }
  </code></pre>
  <p>This works ok when I am treating the data as a short, however if I cast the pointer to a char again the bytes are reversed. What am I doing wrong?</p>