Author | Message | Time |
---|---|---|
Spilled[DW] | 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: [code] 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)); } [/code] Any ideas? I've tried uswest.battle.net 6112, www.google.com 80. Only success was my friends server he ran on the network. =\ | June 27, 2005, 7:33 PM |
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. | June 27, 2005, 9:14 PM |
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 | June 27, 2005, 9:35 PM |
Myndfyr | Don't you use gethostbyname(const char*) to resolve host names to IP host entries? | June 27, 2005, 10:22 PM |
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). | June 27, 2005, 11:32 PM |
Spilled[DW] | 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! | June 28, 2005, 4:13 PM |
Myndfyr | [quote author=Spilled[DW] link=topic=11994.msg117891#msg117891 date=1119975227] 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! [/quote] What's giving you an undeclared error? | June 28, 2005, 9:21 PM |
Spilled[DW] | [quote author=MyndFyre link=topic=11994.msg117946#msg117946 date=1119993680] [quote author=Spilled[DW] link=topic=11994.msg117891#msg117891 date=1119975227] 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! [/quote] What's giving you an undeclared error? [/quote] inet_pton. i tried replacing inet_addr with inet_pton like kp suggested and it said that was undeclared. | June 29, 2005, 8:00 AM |
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 | June 29, 2005, 9:26 PM |
Kp | [quote author=UserLoser link=topic=11994.msg118078#msg118078 date=1120080370]inet_addr should be fine as long as you're not dealing with Ipv6 addresses[/quote] 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. | June 30, 2005, 2:41 AM |
Spilled[DW] | 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 :) | June 30, 2005, 7:25 AM |