|
From: <hor...@te...> - 2003-01-18 14:54:43
|
Hi Everybody,
I have a small problem when initzialising winsock 1.1
Th code I have wrote is as follows:
WSADATA wsaData;
LPHOSTENT lpHostEntry;
LPSERVENT lpServEnt;
SOCKADDR_IN saServer;
lpHostEntry =3D gethostbyname("w1.184.telia.com/~u18414535");
SOCKET Socket;=20
Socket =3D socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (Socket =3D=3D INVALID_SOCKET)
{
MessageBox(NULL,"Unable to create socket","Error", =
MB_OK|MB_ICONEXCLAMATION);=20
=20
}
lpServEnt =3D getservbyname("http", "tcp");
if (lpServEnt =3D=3D NULL)
saServer.sin_port =3D htons(80);
else
saServer.sin_port =3D lpServEnt->s_port;
=20
saServer.sin_family =3D AF_INET;
saServer.sin_addr =3D *((LPIN_ADDR)*lpHostEntry->h_addr_list);
=20
int nRet;
nRet =3D connect(Socket, (LPSOCKADDR)&saServer, =
sizeof(SOCKADDR_IN));
if (nRet =3D=3D SOCKET_ERROR)
{
MessageBox(NULL,"Unable to connect the socket","Error", =
MB_OK|MB_ICONEXCLAMATION);=20
closesocket(Socket);
=20
}
Everything compiles well, but when this code comes in use, I get one og =
these famaus messages "The program has executed an illigeal operation =
and must be terminated".
Why?
Please help me!!!
Thanks in advance!
=20
//Johan H=F6rnell |