HI All, i know its a known issue but i am again back with same problem.I am trying to find IP of the host. USed this code.:
struct sockaddr_in sock_name;
int sock_size = sizeof(sock_name);
struct in_addr remote_addr;
int sockfd, size = 15;
if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)))
{
return;
}
getsockname(sockfd, (struct sockaddr *)&sock_name, (socklen_t*)&sock_size);
remote_addr = sock_name.sin_addr;
sprintf(tempbuff,"%s",inet_ntoa(remote_addr));
DONT GO FOR MISTAKES ITS JUST A PART OF CODE FOR FINDING IP.
Now the problem is that the ip it returns is 0.0.0.0
and i think i have done the right thing opening a socket and then taking the ip to which that socket is associated.
Please dont suggest gethostbyname function. Cant use that function as its not supported in my JVM.
Is there any other way in c to find the ip....or can anybody tell me what i am doing wrong in the code....
thanks for the help
regards
habatra