Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

udp recvfrom() returns no IP address

Status
Not open for further replies.

JediDan

Programmer
May 15, 2002
128
US
Hello,

I have a socket app performing recvfrom(...) on a UDP socket. The data comes across fine, but I don't get an IP address in the sockaddr struct, although I do get a port... Code:

Code:
sockaddr_in sourceAddr;
socklen_t addrLen;

recvfrom(socketfd, buffer, avail, 0, (sockaddr*)&sourceAddr, &addrLen);

inet_ntoa(sourceAddr.sin_addr) gives "0.0.0.0"

ntohs(sourceAddr.sin_port) gives "50717" (or whatever the remote port was, varies of course).

This is running on a Linux box with g++ 4.1.1, and the problem happens with UDP packets sent from either another Linux machine or Windows.

I also notice that when I bind this UDP port, it thinks it's IP address is also 0.0.0.0, although when I bind TCP sockets elsewhere in the app, they correctly determine the machine's IP.

Any ideas?

Thanks,

Dan
 
Have you done
Code:
socklen_t addrLen=sizeof(sourceAddr);
before the recvfrom() statement?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top