title: Extract IP from connection that listen and accept in socket programming in Linux in c
body: <p>In the following code I would like to extract the IP address of the connected client after accepting an incoming connection. What should I do after the <code>accept()</code> to achieve it?</p>
  
  <pre><code>int sockfd, newsockfd, portno, clilen;
  portno = 8090;
  clilen = 0;
  pthread_t serverIn;
  struct sockaddr_in serv_addr, cli_addr;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd &lt; 0)
  {
      perror("ERROR opening socket");
  }
  bzero((char *) &amp; serv_addr, sizeof (serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(portno);
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  if (bind(sockfd, (struct sockaddr *) &amp; serv_addr, sizeof (serv_addr)) &lt; 0)
  {
      perror("ERROR on binding");
  }
  
  listen(sockfd, 5);
  clilen = sizeof (cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *) &amp; cli_addr, &amp;clilen);
  </code></pre>