title: connection error: Invalid argument at sockets
body: <p>I have this code</p>
  
  <pre><code>Server:
  //"sock" has already been created with no problem and binding as well
  
  void Connection::bind_connection(int port){
      cout &lt;&lt; "Port " &lt;&lt; port &lt;&lt; endl;
      server.sin_family = AF_INET ;
      server.sin_addr.s_addr = htonl(INADDR_ANY);
      server.sin_port = htons(port);
      /* Bind socket to address */
      struct sockaddr *serverptr = ( struct sockaddr *) &amp;server;
      if ( bind ( sock , serverptr , sizeof(server) ) &lt; 0) {
          perror("Binding error"); exit(BE);
      }
      cout &lt;&lt; "Server binding completed!" &lt;&lt; endl;
  }    
  
  struct sockaddr_in client ;
  socklen_t clientlen ;
  struct sockaddr * clientptr =( struct sockaddr *) &amp;client ;
  if ( listen (sock , MAX_CONNECTIONS) &lt; 0) {perror("listening error"); exit(LE);}
  cout &lt;&lt; "Listening for connections to port " &lt;&lt; port &lt;&lt; endl;
  while (1) {
      /* accept connection */
      if (( newsock = accept ( sock , clientptr , &amp;clientlen ) ) &lt; 0) {
          perror("Accepting error"); cout &lt;&lt; "Errno = " &lt;&lt; errno &lt;&lt; endl; exit(AE);
      }
      //Code
      ....
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Client:
  //struct sockaddr_in server; &lt;--- declared as data member of class "Connection"
  //"sock" has already been created with no problem
  void Connection::do_connect(){
      struct sockaddr *serverptr = ( struct sockaddr *) &amp;server;
      if ( connect ( sock , serverptr , sizeof (server) ) &lt; 0)
           perror("client connect"); exit(CE);
      cout &lt;&lt; "Client connecting to the server" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>and I get the above message. Most of the code is copied from the lesson slides but modified for my needs. Googling the problem it seems that I give wrong size at the syscall(s). Any idea where exactly the problem is? Thanks in advance.</p>