I've mostly figured out how to port Beejs guide to windows.
I'm trying out the "Gethostbyname" lookup program. And I keep getting linker errors saying,
Undefined reference to "herror"
My source code is as follows, and I'm linking to libwsock32.a
I'm compiling in Dev-C++ 4.9.8.0
Code:#include <stdio.h> #include <stdlib.h> #include <winsock.h> #include <errno.h> int main(int argc, char *argv[]) { WSADATA wsaData; // if this doesn’t work //WSAData wsaData; // then try this instead if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) { fprintf(stderr, "WSAStartup failed.\n"); exit(1); } struct hostent *h; if (argc != 2) { // error check the command line fprintf(stderr,"usage: getip address\n"); exit(1); } if ((h=gethostbyname(argv[1])) == NULL) { // get the host info herror("gethostbyname"); exit(1); } WSACleanup(); printf("Host name : %s\n", h->h_name); printf("IP Address : %s\n", inet_ntoa(*((struct in_addr *)h->h_addr))); system("PAUSE"); return 0; }
Thank you for the help
Michael
PS: If I comment out the line refering to herror, it compiles and runs fine....



LinkBack URL
About LinkBacks


