title: Simple messaging application...getting errno 14: bad address
body: <p>I am writing a simple messaging application in C using sockets. When I use function <code>recvfrom</code>, it returns <code>-1</code> and sets <code>errno = 14</code> which is <code>Bad address</code> (which I am printing at the end).</p>
  
  <p>The strange thing is that it still reads from the socket and gets the correct message. That is, the application is working perfectly and as expected except for that error.</p>
  
  <p>My question is this: Why do you think I am getting this error? I cannot think of any reason. I was using <code>inet_pton</code> to set <code>peer-&gt;sin_addr</code> but I was getting the same error.</p>
  
  <pre><code>// socket file descriptor to send data through
  int recv_sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  
  // fill in the peer's address, loopback in this case
  struct sockaddr_in *peer = malloc(sizeof(struct sockaddr_in));
  peer-&gt;sin_family = AF_INET;
  peer-&gt;sin_port   = htons(11110);
  char *new = &amp;(peer-&gt;sin_addr);
  new[0] = 127;
  new[1] = 0;
  new[2] = 0;
  new[3] = 1;
  for (int i = 0; i &lt; 8; i++) {
      peer-&gt;sin_zero[i] = NULL;
  }
  
  bind(recv_sock_fd, peer, sizeof(struct sockaddr_in)); 
  
  // check to see if the socket has any data...code removed
  
  char buff[32] = {0};
  errno = 0;
  int bytes_received = recvfrom(recv_sock_fd, buff, sizeof(buff), NULL, (struct sockaddr *)peer, sizeof(struct sockaddr_in));
  
  printf("Bytes recieved: %d: %d : %s\n", bytes_received, errno, strerror(errno));
  </code></pre>