title: inet_ntop returns 0.0.0.0 in first usage
body: <p>I'm trying to write server application. I want to get client's ip. My problem is with inet_ntop function. I can't get it working properly. Here is my usage :</p>
  
  <pre><code>void client_loop(uint16_t port) {
       int cfd;
       int socket = bind_socket(port, INADDR_ANY);
       char ip[INET_ADDRSTRLEN];
       struct sockaddr client_addr;
       struct sockaddr_in *addr_in;
       socklen_t cli_len;
       while (work) {
          if ((cfd = TEMP_FAILURE_RETRY(accept(socket, &amp;client_addr, &amp;cli_len))) &lt; 0) {
              if (EAGAIN == errno || EWOULDBLOCK == errno)
                  continue;
              ERR("accept");
         }
         addr_in=(struct sockaddr_in *)&amp;client_addr;
         inet_ntop(AF_INET, &amp;(addr_in-&gt;sin_addr),ip, sizeof(ip)); 
         printf("INET_NTOP: %s\n",ip);
      }
  }
  </code></pre>
  
  <p>First usage of inet_ntop always returns 0.0.0.0 Then it works properly. When im moving inet_ntop  to outside function it works properly only for  connections from localhost. Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>Fixed. The problem was that <strong>cli_len</strong> wasn't initialized so accept wasn't filling <strong>client_addr</strong>.</p>
  
  <p>With this line its working like a boss:</p>
  
  <pre><code>socklen_t cli_len=sizeof(struct sockaddr);
  </code></pre>