title: C Sendto doesn't work when doing it repeatedly
body: <p>I'm facing a weird problem when using sendto() in C. I have this code:</p>
  
  <pre><code>struct sockaddr_in currSocket;
  int currSocketLength = sizeof(currSocket);
  memset((char *)&amp;currSocket, 0, sizeof(currSocket));
  currSocket.sin_family = AF_INET;
  currSocket.sin_port = htons(serverPortNumber);
  // add the server IP address
  inet_aton(serverIP, &amp;currSocket.sin_addr);
  
  int send_result = sendto(masterSocket, bufferToSend , 1000, 0, (struct sockaddr *) &amp;currSocket, currSocketLength);
  if (send_result &lt; 0) {
      perror("Something is wrong");
  }
  bzero(bufferToSend, 1000);
  </code></pre>
  
  <p>This works great when I send data the first time in <code>bufferToSend</code>. However, if I want to send data again the exact same way (following the code above - create the socket and send it there), it doesn't get received. Why is this and how can I fix it?</p>
  
  <p>Edit:
  After looking into it some more, I've realized it's because my IP address string is wrong because it's being overwritten. It seems to have it's value change after I do a previous read. </p>
  
  <pre><code>// here the IP address is fine
  printf("%s\n", ipAddress);
  char bufferFromSocket[512];
  int amount_read = read(masterSocket, bufferFromSocket, 512);
  // here the IP address is overwritten by whatever is in bufferFromSocket
  printf("%s\n", ipAddress);
  </code></pre>
  
  <p>Any ideas why this could be happening?</p>