You need to initialize winsock before using any winsock function:
Code:
int main(int argc, char *argv[])
{
struct hostent *h;
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
printf("Failed to initialize!\n");
return -1;
}
if(argc !=2)
{
fprintf(stderr,"Argument error!");
exit(1);
}
h=gethostbyname(argv[1]);
if(h==NULL)
{
fprintf(stderr,"gethostbyname error!");
exit(1);
}
printf("\nHost name: %s",h->h_name);
printf("IP adress: %s",inet_ntoa(*((struct in_addr *)h->h_addr)));
}