How to do that with winsock1.1?
Posted on 2003-12-26 23:38:39 by optimus
socket means (IP+PORT) UDP or TCP

4 example: tcp and udp are two different sockets
Posted on 2003-12-27 05:14:34 by etn
I mean the handle of a socket, or hSock.
Posted on 2003-12-27 10:45:26 by optimus

use getpeername()

Posted on 2003-12-27 15:58:57 by ancev
i can't work successfully with this API (always get a incorrent result). any proved code can be given?
Posted on 2003-12-28 04:06:52 by optimus
You are looking at the wrong element - try looking closer at the sockaddr_in structure with which your socket handle is associated.
Posted on 2003-12-28 16:45:19 by Homer
i guess so.
any code?
Posted on 2003-12-28 19:46:23 by optimus
If you want source, you should search the board.
You don't need to use GetPeerName at all.
Firstly, if the socket is a client socket connected to a remote server, you ALREADY know the server ip since you connected to it.
Secondly, if the socket is a server socket with a remote client connecting, then Accept has already put their ip address in the sin_addr.S_un.S_addr field of the sockaddr_in structure.
The ONLY time you need to use GetPeerName is when you want to look at the remote address BEFORE calling Accept, for example if you wish to deny connection to a certain ip or block of ip addresses.
Have a nice day :)
Posted on 2003-12-29 05:59:20 by Homer
then after ACCEPT the sock
what should be done to retrieve the IP address?
Posted on 2003-12-29 23:45:20 by optimus
fetch the dword value from sockaddr_in.sin_addr.S_un.S_addr, thats the ip address stored as a dword. Each byte in the dword represents one of the four parts of the ip address.
Posted on 2003-12-30 00:19:13 by Homer
i tried, but there is some problem

when i do like this:

invoke accept,cfg.hSocket,0,0

it worked just fine

when i do like this:

LOCAL inaddr:sockaddr_in
invoke accept,cfg.hSocket,addr inaddr,sizeof inaddr

no socket can be accepted. why?
Posted on 2003-12-30 00:33:21 by optimus