title: C++ getpeername returns 0.0.0.0:0
body: <p>I'm trying to get IP and Port of client, connected to the server socket. I pass the following function client socket file descriptor, but it returns 0.0.0.0:0
  This drives me crazy, but <strong>sometimes</strong> it returns something like 248.127.0.0:24870...
  What am I doing wrong?</p>
  
  <p>PS returned address length is 16. Result returned by function is 0. No errors occur.</p>
  
  <pre><code>void    SocketServer::Log ( int socketFD , string message )
  {
      struct sockaddr                     address;
      socklen_t                           addressLength;
      struct sockaddr_in*                 addressInternet;
      string                              ip;
      int                                 port;
  
      int result = getpeername ( socketFD , &amp;address , &amp;addressLength );
      cout &lt;&lt; "Address length is " &lt;&lt; addressLength &lt;&lt; "     Return is " &lt;&lt;  result &lt;&lt; "\n";
      addressInternet = (struct sockaddr_in*)&amp;address;
  
      ip = inet_ntoa ( addressInternet-&gt;sin_addr );
      port = ntohs ( addressInternet-&gt;sin_port );
  
      cout &lt;&lt; "Socket FD is " &lt;&lt; socketFD &lt;&lt; " " &lt;&lt; ip &lt;&lt; ":" &lt;&lt; port &lt;&lt; " " &lt;&lt;  message &lt;&lt; "\n";
  };
  </code></pre>