• Welcome to Valhalla Legends Archive.
 

Winsock Issues

Started by Spilled, June 27, 2005, 02:33 PM

Previous topic - Next topic

Spilled

Adding a winsock to my project I ran into a problem. I can connect to my friends computer at school from mine but any outside destination I recieve a memory error.
here is my connect:

void wSockConnect()
{
WORD wVersion;
WSADATA wsData;

/* Initialize Socket */
wVersion = MAKEWORD(1,1);
WSAStartup(wVersion, &wsData);

LPHOSTENT hostData;
in_addr ipHost;
char* hostText[16];

/* read config here */
//hostText[16] = "168.156.223.149";

ipHost.s_addr = inet_addr("uswest.battle.net");
hostData = gethostbyaddr((const char FAR*)&ipHost, sizeof (in_addr), AF_INET);

/* make socket */
wSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

/* fill sockaddr_in with address info */
SOCKADDR_IN hostInfo;

hostInfo.sin_family = AF_INET;

hostInfo.sin_addr = *((LPIN_ADDR)*hostData->h_addr_list);

hostInfo.sin_port = htons(6112);
int ret = connect(wSock, (LPSOCKADDR)&hostInfo, sizeof(sockaddr));
}

Any ideas? I've tried uswest.battle.net 6112, www.google.com 80. Only success was my friends server he ran on the network. =\

R.a.B.B.i.T

Sounds like the network is blocking your program's access.  It's a fairly common system firewalls use to block trojans/spyware/adware from downloading other stuff.

UserLoser.

inet_addr takes in a Ipv4 dotted address, not a hostname.  If you were to check what inet_addr was returning, you would see it would probably be equal to INADDR_NONE

MyndFyre

Don't you use gethostbyname(const char*) to resolve host names to IP host entries?
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.

Kp

Also, it's worth noting that inet_addr is deprecated and you should instead use inet_pton (which itself supersedes inet_aton, which superseded inet_addr).
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Spilled

I've tried using the actual ip of the battle.net Server also and no connection. IE I tried inet_pton and it's giving me an undeclared error. All help is appreciated!

MyndFyre

Quote from: Spilled[DW] on June 28, 2005, 11:13 AM
I've tried using the actual ip of the battle.net Server also and no connection. IE I tried inet_pton and it's giving me an undeclared error. All help is appreciated!

What's giving you an undeclared error?
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.

Spilled

Quote from: MyndFyre on June 28, 2005, 04:21 PM
Quote from: Spilled[DW] on June 28, 2005, 11:13 AM
I've tried using the actual ip of the battle.net Server also and no connection. IE I tried inet_pton and it's giving me an undeclared error. All help is appreciated!

What's giving you an undeclared error?

inet_pton. i tried replacing inet_addr with inet_pton like kp suggested and it said that was undeclared.

UserLoser.

I'm pretty sure inet_aton and inet_pton are not used on Windows.  inet_addr should be fine as long as you're not dealing with Ipv6 addresses

Kp

Quote from: UserLoser on June 29, 2005, 04:26 PMinet_addr should be fine as long as you're not dealing with Ipv6 addresses

True, assuming he also does his own error handling.  Certain versions of ping are unable to ping 255.255.255.255, due to the design flaw in inet_addr.  The solution is to upgrade to a ping which uses inet_aton or inet_pton.  Unfortunately, you're correct that Microsoft Windows has neither of those calls, thus burdening the application programmer with working around the shortcomings of inet_addr.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Spilled

Problem Solved -- sat down at school for 3 hours studying all the winsock sources on google i could find :)
thanks for all your help once again guys :)