if (connect(Socket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) != 0)
{
errorp = "Failed to establish connection with server";
}
else
errorp = "Connected";
return 0;
}
I know for a fact the DNS goes fine, because if you enter a bogus adress it fails, however every time you attempt a connect it will say, "Failed to establish connection with server"
Question
HerbDX
Hi, i'm working on an irc project with vc6, and i've recently come into troubles about the connections..
Here is the code in full:
short WINAPI DLLExport Connect(LPRDATA rdPtr, long param1, long param2)
{
char * p1=(LPSTR)param1;
//Initialize some stuff
WSADATA WsaDat;
if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0)
{
errorp = "WSA Initialization failed";
}
//Open a socket
Socket = socket(AF_INET, SOCK_STREAM, 0);
if (Socket == INVALID_SOCKET)
{
errorp = "Socket creation failed";
}
char Name[255];
gethostname(Name, 255);
SockAddr.sin_port = 6667;
HOSTENT *HostInfo;
HostInfo = gethostbyname(p1);
if (HostInfo == NULL)
{
errorp = "DNS could not be resolved";
}
else
{
SockAddr.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)HostInfo->h_addr_list[0][0];
SockAddr.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)HostInfo->h_addr_list[0][1];
SockAddr.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)HostInfo->h_addr_list[0][2];
SockAddr.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)HostInfo->h_addr_list[0][3];
}
//Connect
if (connect(Socket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) != 0)
{
errorp = "Failed to establish connection with server";
}
else
errorp = "Connected";
return 0;
}
I know for a fact the DNS goes fine, because if you enter a bogus adress it fails, however every time you attempt a connect it will say, "Failed to establish connection with server"
Help would be much much appreciated
Thanks
Link to comment
Share on other sites
3 answers to this question
Recommended Posts