title: Determining the IP address of a connected client on the server
body: <p>I have a server running on one machine and have the port it uses forwarded to my router, and another machine running the client connecting to the server using my <em>ISP assigned external IP address</em> instead of the local address. This all works fine and it connects but When I check the address of the connected socket (client), The IP address that it shows is completely different? it shows me <code>148.49.68.0</code>. I can't find this on ipconfig and don't understand where this is popping up from. Shouldn't the client show my external address? (seeing as both computers use the same External IP address).</p>
  
  <p><strong>[EDIT]</strong> added server source</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;winsock2.h&gt;
  #include &lt;ws2tcpip.h&gt;
  #include &lt;string.h&gt;
  using namespace std;
  
  int PORT;
  const int winsock_version = 2;
  const int max_con = 10;
  string SERVER_ADDRS;
  
  void Bind(SOCKET &amp;serv,struct sockaddr_in &amp;serv_info,int size);
  void Listen(SOCKET &amp;serv,int max_con);
  void connection_info(struct sockaddr_in &amp;client);
  bool communication(SOCKET &amp;client); 
  SOCKET Accept(SOCKET &amp;serv);
  
  int main(void){
  
      WSADATA wsadata;
      if ( WSAStartup(MAKEWORD(winsock_version,0),&amp;wsadata) == 0 ){
          cout&lt;&lt;"-[Initialized.]" &lt;&lt; endl;
          cout&lt;&lt;"-[Server Address (leave blank to scan for all IP's)]: ";
          getline(cin,SERVER_ADDRS);
          cout&lt;&lt;"-[Port]: ";
          cin&gt;&gt;PORT;
  
          struct sockaddr_in serv_info;
          serv_info.sin_family = AF_INET;
          serv_info.sin_port = htons(PORT);
          if( sizeof(SERVER_ADDRS) &gt; 5 ){
              cout&lt;&lt;"-[Listening on: " &lt;&lt; SERVER_ADDRS &lt;&lt; "]" &lt;&lt; endl;
              serv_info.sin_addr.s_addr = inet_addr(SERVER_ADDRS.c_str());
          }else{
              cout&lt;&lt;"-[Scanning for All IP's]" &lt;&lt; endl;
              serv_info.sin_addr.s_addr = INADDR_ANY;
          }
  
          SOCKET serv;
          serv = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
          if ( serv != INVALID_SOCKET ){
              //------------------------------------------------------------
              Bind(serv,serv_info,sizeof(serv_info));
              Listen(serv,max_con);
  
  
              struct sockaddr_in client_info;
              int size = sizeof(client_info);
  
              SOCKET client_sock = Accept(serv);
              connection_info(client_info);
  
              if (communication(client_sock) == true){
                  closesocket(serv);
                  closesocket(client_sock);
              }
              //------------------------------------------------------------
          }
  
      }else{
          cout&lt;&lt;"-[Initialization failed, running cleanup.]" &lt;&lt; endl;
      }
  
      if (WSACleanup() == 0){
          cout&lt;&lt;"-[Cleanup Successful.]" &lt;&lt; endl;
      }
  
      return 0;
  }
  
  void Bind(SOCKET &amp;serv,struct sockaddr_in &amp;serv_info,int size){
  
      if ( bind(serv,(sockaddr*)&amp;serv_info,size) != -1 ){
          //Binding complete, now clear the port and allow for reuse if needed using setsockopt
          char yes = '1';
          if ( setsockopt(serv,SOL_SOCKET,SO_REUSEADDR,&amp;yes,sizeof(yes)) != SOCKET_ERROR){
                  cout&lt;&lt;"-[Binding Successful.]" &lt;&lt; endl;
          }
      }
  }
  
  void Listen(SOCKET &amp;serv,int max_con){
      if ( listen(serv,max_con) != -1 ){
          cout&lt;&lt;"-[Listening for connections.] " &lt;&lt; endl;
      }
  }
  
  SOCKET Accept(SOCKET &amp;serv){
  
      struct sockaddr_in client_info;
      int size = sizeof(client_info);
      SOCKET recv;
  
      recv = accept(serv,(sockaddr*)&amp;client_info,&amp;size);
      if (recv != INVALID_SOCKET ) {
          return recv;
      }else{
          cout&lt;&lt;"-[Invalid Socket.]" &lt;&lt; endl;
      }
  }
  
  void connection_info(struct sockaddr_in &amp;client){
      char *connected_ip= inet_ntoa(client.sin_addr); 
      int port = ntohs(client.sin_port);
  
      cout&lt;&lt;"-[IP:" &lt;&lt; connected_ip &lt;&lt;", Connected on PORT:"&lt;&lt; port  &lt;&lt; "]"&lt;&lt; endl;
  }
  
  bool communication(SOCKET &amp;client){
      cout&lt;&lt;"[---------------{CHAT}---------------]" &lt;&lt; endl;
      int bytes_in;
      int bytes_out;
      char recvd_text[80];
      string send_text;
  
      while(true){
          cout&lt;&lt;"-[SERVER]: ";
          getline(cin,send_text);
          if (sizeof(send_text) &gt; 0 ){
              bytes_out = send(client,send_text.c_str(),send_text.length()+1,0);
              cout&lt;&lt; endl;
              if (bytes_out == SOCKET_ERROR){
                  cout&lt;&lt;"-[SERVER error in sending.]" &lt;&lt; endl;
                  break;
              }
          }
  
          bytes_in = recv(client,recvd_text,sizeof(recvd_text),0);
          if (bytes_in &gt; 0 ){
              cout&lt;&lt;"-[CLIENT]: " &lt;&lt; recvd_text &lt;&lt; endl;  //output on screen
          }
          if (bytes_in == 0){
              cout&lt;&lt;"-[CLIENT has disconnected.]" &lt;&lt; endl;
              break;
          }
          if (bytes_in == SOCKET_ERROR){
              cout&lt;&lt;"-[CLIENT closed unexpectedly.]" &lt;&lt; endl; 
              break;
          }
  
      }
      return true;
  }
  </code></pre>