Hi guys,
I need to write a programme, when it executes, it should display the hostname and the ip address of the machine it resides. I have written a code. It gives the username. But it dosent gives the correct ip address?
Pls help me to solve this?
Code:int main() { char abc[MAX_PATH]; WSADATA wsaData; SOCKET sockfd; WSAStartup(MAKEWORD(2, 0),&wsaData); sockfd=socket(AF_INET,SOCK_STREAM,0); struct sockaddr_in sa; struct hostent *hp; gethostname(abc, sizeof(abc)); puts(abc); hp = gethostbyname(abc); sa.sin_family = hp->h_addrtype; printf("\n\n%s\n\n",inet_ntoa(sa.sin_addr)); system("pause"); }



LinkBack URL
About LinkBacks


