hi
the socket is returned by accept,
how could i get client's ipaddress from this socket?

thanks

terry
Posted on 2002-01-05 11:53:48 by xqterry
you can set the addr parameter of accept to a pointer to an empty sockaddr_in structure. On return this structure contains the IP address (lookup sockaddr or sockaddr_in in the winsock reference).

Thomas
Posted on 2002-01-05 12:03:32 by Thomas
hi Thomas

.IF ax==FD_ACCEPT
INVOKE accept,listensock,offset sockaddr,sizeof sockaddr
INVOKE WSAAsyncSelect,eax,hwnd,WM_SOCKET,FD_READ or FD_CLOSE
.ELSEIF ax==FD_READ
......................


Then,I write to log file on another message proc,I am not sure this addr hasn't been changed, I always think if others connect the server,maybe sockaddr will change.
Is it right?

Terry
Posted on 2002-01-05 12:22:29 by xqterry
First of all, this code won't work as the last parameter of accept is a *pointer* to the size of sockaddr, and not the size itself. Use some dword variable, put sizeof sockaddr in it and pass a pointer to that var as parameter for accept.

And yes the address can change as FD_ACCEPT is sent on each request for a connection. You need to handle these requests somehow.

Thomas
Posted on 2002-01-05 12:32:49 by Thomas
hi Thomas

first, i am sorry i have made same fault twice. :(

Then, I read winsock api ref, Could the function getsockname get client' ip?

thanks

terry
Posted on 2002-01-05 12:44:29 by xqterry
Well you could do that to get the address, but you still need some synchronization in your server.
I mean, when you have multiple connections, you have to deal with them seperately and don't get things mixed up.
I don't know what kind of server you are creating but make sure you use the right socket at the right time..

Thomas
Posted on 2002-01-05 12:59:09 by Thomas
:)

OK, i will be careful.

you are really patient.

thanks for all

Terry
Posted on 2002-01-05 13:03:53 by xqterry