I'm doing some Dev in connecting to the internet using some API calls. I'm having some problems with one part of it that I'm hoping someone can help me out on. Here is the main part of the code that I have.....
//General local variables
WSADATA wsaData;
//if err is anything other than 0, there was an error
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
{
AfxMessageBox("failed"
return false;
}
IN_ADDR iaHost;
LPHOSTENT lpHostEntry;
int err;
iaHost.s_addr = inet_addr(" lpHostEntry = gethostbyname("
if (lpHostEntry == NULL)
{
AfxMessageBox((_bstr_t)(long)(WSAGetLastError()));
return 0;
}
SOCKET Socket;
Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (Socket == INVALID_SOCKET)
{
AfxMessageBox((_bstr_t)(long)(WSAGetLastError()));
return 0;
}
LPSERVENT lpServEnt;
SOCKADDR_IN saServer;
lpServEnt = getservbyname("http", "tcp"
if (lpServEnt == NULL)
saServer.sin_port = htons(80);
else
saServer.sin_port = lpServEnt->s_port;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
err = connect(Socket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));
if (err == SOCKET_ERROR)
{
AfxMessageBox((_bstr_t)(long)(WSAGetLastError()));
return 0;
}
Everytying works great until I get to the connect statement. It gives me a "host unreachable" error. I'm not sure why. As far as I can tell, everything up to this point goes okay. I am trying to go through a firewall, so I'm not sure if this could cause a problem. I'm new to this type of programming, so any and all help is greatly appreciated. Thanks in advance!!
Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
//General local variables
WSADATA wsaData;
//if err is anything other than 0, there was an error
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
{
AfxMessageBox("failed"
return false;
}
IN_ADDR iaHost;
LPHOSTENT lpHostEntry;
int err;
iaHost.s_addr = inet_addr(" lpHostEntry = gethostbyname("
if (lpHostEntry == NULL)
{
AfxMessageBox((_bstr_t)(long)(WSAGetLastError()));
return 0;
}
SOCKET Socket;
Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (Socket == INVALID_SOCKET)
{
AfxMessageBox((_bstr_t)(long)(WSAGetLastError()));
return 0;
}
LPSERVENT lpServEnt;
SOCKADDR_IN saServer;
lpServEnt = getservbyname("http", "tcp"
if (lpServEnt == NULL)
saServer.sin_port = htons(80);
else
saServer.sin_port = lpServEnt->s_port;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
err = connect(Socket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));
if (err == SOCKET_ERROR)
{
AfxMessageBox((_bstr_t)(long)(WSAGetLastError()));
return 0;
}
Everytying works great until I get to the connect statement. It gives me a "host unreachable" error. I'm not sure why. As far as I can tell, everything up to this point goes okay. I am trying to go through a firewall, so I'm not sure if this could cause a problem. I'm new to this type of programming, so any and all help is greatly appreciated. Thanks in advance!!
Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com