I'm trying to learn networking in C++, but whenever I compile this I get a bunch of 'undeclared identifiers' etc. If I compile it with <winsock2.h> I get about 86 errors, and when I click on them it takes me to the actual winsock2.h header file. I've included winsock32.lib and wsock32.lib in my linker options too.. Here's what I have so far:
Code:
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <winsock.h>
using std::cout;
using std::cin;
using std::endl;
WSADATA wsaData;
int main() {
struct addrinfo hints, *servinfo = NULL;
int wsaReturnVal = WSAStartup(MAKEWORD(1, 1), &wsaData);
if (wsaReturnVal) {
cout << "Error number: " << wsaReturnVal << endl;
exit(1);
}
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
int status = getaddrinfo(NULL, "3490", &hints, &servinfo);
if (status == -1) {
cout << "getaddrinfo error." << endl;
exit(1);
}
freeaddrinfo(servinfo);
if (WSACleanup()) {
cout << "Cleanup Error." << endl;
exit(1);
}
}
The errors I get for this compile are:
Error 1 error C2079: 'hints' uses undefined struct 'main::addrinfo' 13
Error 2 error C2228: left of '.ai_flags' must have class/struct/union 20
Error 3 error C2065: 'AI_PASSIVE' : undeclared identifier 20
Error 4 error C2228: left of '.ai_family' must have class/struct/union 21
Error 5 error C2228: left of '.ai_socktype' must have class/struct/union 22
Error 6 error C3861: 'getaddrinfo': identifier not found 24
Error 7 error C3861: 'freeaddrinfo': identifier not found 30
Thanks.
EDIT: Here's a screenshot of winsock2.h errors.. http://img56.imageshack.us/my.php?im...5112335jf3.jpg