• Welcome to Valhalla Legends Archive.
 

Strange Winsock2 Errors

Started by Yegg, August 08, 2005, 10:12 AM

Previous topic - Next topic

Yegg

I've trying to get used to using Winsock2.h, however when I try my code out I receive strange errors. Here is the code, below it are the error messages.

#include <winsock2.h>
#include <stdio.h>

int main() {
SOCKET MainSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(MainSocket == INVALID_SOCKET) {
printf ("Error connecting socket!\n");
return 0;
}
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr("asia.battle.net");
clientService.sin_port = htons(6112);
if(connect(MainSocket, (SOCKADDR*) &clientService, sizeof(clientService)) == SOCKET_ERROR) {
printf("Failed to connect!\n");
WSACleanup();
return 0;
}
printf("Connected to server.\n");
WSACleanup();
char buf[] = "\x03\x04CleanSlateBot\npasswordhere\n";
send(MainSocket, buf, sizeof(buf), 0);

return 0;
}


Text1.obj : error LNK2001: unresolved external symbol __imp__send@16
Text1.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
Text1.obj : error LNK2001: unresolved external symbol __imp__connect@12
Text1.obj : error LNK2001: unresolved external symbol __imp__htons@4
Text1.obj : error LNK2001: unresolved external symbol __imp__inet_addr@4
Text1.obj : error LNK2001: unresolved external symbol __imp__socket@12
Debug/test.exe : fatal error LNK1120: 6 unresolved externals


Any help is appreciated.

Warrior

You need to include the winsock library in your project.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

UserLoser.

The following doesn't work and will always return bad:

inet_addr("asia.battle.net");


See msdn, it says "The inet_addr function converts a string containing an (Ipv4) Internet Protocol dotted address into a proper address for the IN_ADDR structure."

MyndFyre

To resolve an internet URL, you want gethostbyname.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

warz

You may also need to do the following two things before you can use your socket.


WSADATA SocketData;
WSAStartup(MAKEWORD( 2, 2 ), &SocketData);

Yegg

Thanks guys but I've already got the problems solved. I added ws2_32.lib to my project and I realized that inet_addr() will only accept the actual server ip. I thought I deleted my post but I guess Im not allowed to.

Warrior

No need, perhaps someone can learn from this.

Good luck.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?