title: how to find a socket's ip address c++/c
body: <p>I want to know how to get the IP address of a client who connects to a socket on a server using accept.  How would I do this? getpeername returns a wrong IP address, and I can't seem to find another way to do it.</p>
  
  <p>On the server, after accept returns, I'm doing this:</p>
  
  <pre><code>            char buf[INET_ADDRSTRLEN];
              struct sockaddr name; socklen_t len = sizeof(name);
              getpeername(sock_fd, &amp;name, &amp;len); //sock_fd is the socket im using
              inet_ntop(AF_INET, &amp;name, buf, INET_ADDRSTRLEN);
              string ip = buf;
  </code></pre>