#include <stdio.h>
#include <winsock.h>
int main (int argc, char** argv)
{
struct sockaddr_in addr;
struct hostent* h;
char buffer[BUFSIZ];
char* tmp;
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData)) {
fprintf(stderr, "Error: WSAStartup failed.\n");
return 1;
}
if (argc == 1) {
printf("host: ");
fgets(buffer, sizeof(buffer), stdin);
if ((tmp = strchr(buffer, '\n')) != NULL)
*tmp = '\0';
h = gethostbyname(buffer);
}
else {
h = gethostbyname(argv[1]);
}
if (h == NULL) {
//herror("Error: gethostbyname");
fprintf(stderr, "Error: gethosbyname() failed.\n");
WSACleanup();
return 1;
}
addr.sin_addr = *(struct in_addr*) h->h_addr;
printf("ip: %s", inet_ntoa(addr.sin_addr));
WSACleanup();
return 0;
}