Originally Posted by
carrotcake1029
With that kind of error it means you did not. Are you compiling this via command line or are you using an IDE. If its command line, try adding this switch: -lws2_32
Yes, you are correct. I must've got mixed up trying different ones.
However, I'm still having some issues:
It hits the code CommonTater suggested and exists. Is it just my system?
Code:
#pragma comment(lib, "ws2_32")
#include <stdio.h>
#include <winsock.h>
int main(int argc, char *argv[])
{
int i;
struct hostent *he;
struct in_addr **addr_list;
if (argc != 2) {
fprintf(stderr,"usage: ghbn hostname\n");
//getchar();
return 1; //exits here
}
he = gethostbyname(argv[1]);
if (!he) {
puts("Host not found");
return 2;
}
// print information about this host:
printf("Official name is: %s\n", he->h_name);
printf(" IP addresses: ");
addr_list = (struct in_addr **)he->h_addr_list;
for(i = 0; addr_list[i] != NULL; i++) {
printf("%s ", inet_ntoa(*addr_list[i]));
}
printf("\n");
return 0;
}