0

I have taken a simple Server & Client programmes of TCP. I have 2 different networks provided by ISP1 and ISP2 respectively. Server is running on network of ISP1, for which i have done port forwarding on router so that it can accept remote connection and Client is on network of ISP 2, both can communicate well. Now i want to know the ip address of Client for that i am using inet_ntoa(..) function on Server side the problem is that i am getting the destination ip address as public ip address of ISP1 instead it should get public ip address of ISP2.

code snippet:

if ((new_socket = accept(server_fd, (struct sockaddr *)&cli_address, 
                   (socklen_t*)&cli_addrlen))<0)
{
    perror("accept");
    exit(EXIT_FAILURE);
}

printf("Client ip address:%s",inet_ntoa(cli_address.sin_addr));
printf("\t");
printf("Client port:%d",ntohs(cli_address.sin_port));
printf("\n");

I try to probe it on wireshark running on Server side, there also i could not find the Client ip address it displays destination ip address as public ip address of network ISP1 for that packet.

2
  • Why do you think you might get the internal workings of another network when it is doing port forwarding? That is the point of it
    – Ed Heal
    Dec 25, 2017 at 17:43
  • Thanks! @EdHeal but the problem is then how to get the client's ip address which is in another network. to make question simpler, My server is behind router(in my private network) which is connected to internet and Clients are on internet. How can I get the ip address of Clients because every time the actual address of client is lost at router.
    – Wasim
    Dec 26, 2017 at 6:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.