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. =\
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.
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
Don't you use gethostbyname(const char*) (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostbyname_2.asp) to resolve host names to IP host entries?
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).
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 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?
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.
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
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.
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 :)