I am trying to create two C++ applications that communicate with the UDP transport protocol in the Linux operating system. I am using Berkeley sockets.
The client sends a datagram using the sendto function and the server receives the packet with recvfrom like this:
recsize = recvfrom(sock, (void *) buffer, 1024, 0, (struct sockaddr *) &sa, &fromlen);After receiving the datagram, the server prints the sender's IP address and port using the structure sockaddr_in sa filled by the recvfrom function. If I test both the client and the server on my localhost (127.0.0.1), the server successfully prints the correct sender's IP and port. But when I put the server on a different machine from the Internet, the server's receivefrom function doesn't fill the sa structure with the source address and port and it prints the IP 0.0.0.0 and the port 0. My local machine is behind a NAT. So the IP printed by the server would normally be my external IP address and a random port chosen by the NAT protocol which maps to my internal IP and port.
What is the problem?


Sign In
Create Account

Back to top









