Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Internet connectivity...please help

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
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
 

Try to ping the destination. This will tell you if it's your code or the host is actually unreachable. No use trouble shooting code that works.

Brother C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top