![]() |
| | #1 | |
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| addrinfo Structure Not Working 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);
}
}
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
__________________ Quote:
Last edited by pobri19; 10-21-2008 at 07:30 AM. | |
| pobri19 is offline | |
| | #2 | |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,831
| MSDN says: Quote:
| |
| tabstop is online now | |
| | #3 | |
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| Tried that, didn't work. It gets the same errors as Winsock2.h
__________________ Quote:
| |
| pobri19 is offline | |
| | #4 | |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,831
| Found on msdn: Quote:
| |
| tabstop is online now | |
| | #5 | |
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| Alright so just leave out the #include <windows.h> and put #include <winsock2.h> and I should be sweet? I'll try that when I get home and post if it worked. Thanks.
__________________ Quote:
| |
| pobri19 is offline | |
| | #6 | |
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| Alright that didn't work, I removed the Windows.h, and tried just using iostream and winsock.h, which produced the same undeclared identifiers errors, so I tried winsock2.h with iostream, which also produced the exact same errors. any ideas?
__________________ Quote:
| |
| pobri19 is offline | |
| | #7 |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,059
| Add #include <ws2tcpip.h> to your code |
| BobS0327 is offline | |
| | #8 | |
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| Alright so now I have: Code: #include <iostream> #include <winsock2.h> #include <ws2tcpip.h> Code: Error 1 error LNK2001: unresolved external symbol __imp__freeaddrinfo@4 net.obj Error 2 error LNK2001: unresolved external symbol __imp__getaddrinfo@16 net.obj Error 3 fatal error LNK1120: 2 unresolved externals
__________________ Quote:
| |
| pobri19 is offline | |
| | #9 |
| Registered User Join Date: Mar 2005 Location: Mountaintop, Pa
Posts: 1,059
| Link with WS2_32.lib |
| BobS0327 is offline | |
| | #10 | |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,831
| You are aware that you can search MSDN just as well as the rest of us? If you type in "getaddrinfo" and click on the result and go to the bottom you should see this: Quote:
| |
| tabstop is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Still confused why working set larger than virtual memory | George2 | Tech Board | 4 | 01-13-2008 02:14 AM |
| trouble getting structure variables to work across functions | cpudaman | C++ Programming | 13 | 12-14-2007 03:34 PM |
| Switch structure not working | him61 | C++ Programming | 8 | 05-23-2007 05:35 PM |
| structure ...solution plz???? | hegdeshashi | C Programming | 4 | 07-24-2006 09:57 AM |
| How to call a function several times, but with a different structure as argument? | mabuhay | C Programming | 5 | 02-14-2006 09:04 AM |