Re: [Dev-C++] How to use WSAGetLastError?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <qa...@ho...> - 2003-01-27 15:36:21
|
The only difference in your code compared to mine is this.
Your code:
if(bind(sock,(struct sockaddr*)&server,sizeof(struct sockaddr))=3D=3D-1)
My code:
if(bind(sock,(struct sockaddr*)&server,sizeof(server))=3D=3D-1)
Hope it helps...
/J
*********** REPLY SEPARATOR ***********
On 2003-01-27 at 13:40 Vlada Djurovic wrote:
>Hi.
>I'm trying to create a WinSock app. I created a socket, but bind() returns
>an error, so I tried WSAGetLastError to get error code. Here's the code:
>
>case ID_SOCK_OPEN:
> {
> OpenSocket(PORT);//in this function I create socket
> int error=3DWSAGetLastError();
> char buffer[100];
> itoa(error,buffer,2);
> MessageBox(NULL,buffer,"Error Code",MB_OK);
> }
> break;
>In message box I get 0, so I suppose something is wrong about this. Can
>anybode tell me better way to get error code?
>Another question: Here's the code for OpenSocket function. Can somebody
>figure out why call to bind() fails?
>
>BOOL OpenSocket(int port)
>{
> if(sock=3Dsocket(AF_INET,SOCK_STREAM,0)=3D=3D-1)
> {
> MessageBox(NULL,"Could not create
>socket","Error",MB_OK|MB_ICONSTOP);
> return FALSE;
> }
> server.sin_family=3DAF_INET;
> server.sin_port=3Dhtons(port);
> server.sin_addr.s_addr=3DINADDR_ANY;
>
> if(bind(sock,(struct sockaddr*)&server,sizeof(struct=
sockaddr))=3D=3D-1)
> {
> MessageBox(NULL,"Bind error","Error",MB_OK|MB_ICONSTOP);
> return FALSE;
> }
>
> if(listen(sock,3)=3D=3D-1)
> {
> MessageBox(NULL,"Listen error","Error",MB_OK|MB_ICONSTOP);
> return FALSE;
> }
> else
> {
> MessageBox(NULL,"Socket opened","Success",MB_OK);
> return TRUE;
> }
>}
>
>Thanks in advance.
>------------
>Vlada
>
>
>
>-------------------------------------------------------
>This SF.NET email is sponsored by:
>SourceForge Enterprise Edition + IBM + LinuxWorld =3D Something 2 See!
>http://www.vasoftware.com
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
L
|