title: sockaddr_in gets wrong IP address, cpp
body: <p>I am trying to implement a simple client that connects to a give address. You'll notice that I'm printing the given address and the IP address and port after I put it in my sockaddr_in struct.
  I get two different addresses even though it should be the same.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>int createConnection(char * address, char * port) {
      cout &lt;&lt; address &lt;&lt; " " &lt;&lt; port &lt;&lt; endl;
      struct sockaddr_in server;
      server.sin_family = AF_INET;
      server.sin_port = htons(atoi(port));
      inet_aton(address,&amp;(server.sin_addr));
      memset(&amp;(server.sin_zero), '\0', 8);
      if ((sockFd = socket(PF_INET,SOCK_STREAM,0)) == -1) {
          perror("client: socket");
      }
      if (connect(sockFd,(const sockaddr *)&amp;server,sizeof(struct sockaddr_in)) == -1) {
          close(sockFd);
          perror("client: connect");
      }
  
      char s[INET_ADDRSTRLEN];
      inet_ntop(AF_INET, (struct sockaddr *)&amp;server, s, sizeof s);
      printf("client: connecting to %s, %i\n", s, server.sin_port);
      printf("connected");
      return 0;
  }
  </code></pre>
  
  <p>And the output is </p>
  
  <pre><code>132.65.151.39 3000
  client: connecting to 2.0.11.184, 47115
  </code></pre>
  
  <p>My questions:</p>
  
  <ol>
  <li>Why do I see two different addresses?</li>
  <li>How come the connection does not fail?</li>
  </ol>
  
  <p>What happens is that my program is blocked in recv() later on, so I think it didn't connect to where I wanted it. Thanks!</p>