Get IP Address from a socket.
Can someone please provide an example on how to get the IP Address of a socket. I mean the computer IP that initiaited the connection with my server. I want the IP Address in string form. You know: x.x.x.x
Will a mod please delete all my other WinSock topics for I have solved them?
I am using the RAW WinSock API not the WinSock API that MFC provides but the one provided by wsock32.lib.
[406 byte] By [
Guidosoft] at [2007-11-19 17:46:02]

# 2 Re: Get IP Address from a socket.
Im Not Using Mfc Sockets I Am Using The Regular Winsock Api With Mfc!!!
I Am Using The Mfc Api But Not The Winsock Api It Provides I Am Using The Standard Windows Winosck Api!!!!!!!
# 5 Re: Get IP Address from a socket.
checkout getsockname() and getpeername() APIs.
For the IP address of the remote client connected on the socket.
The getpeername function retrieves the name of the peer to which a socket is connected.
int getpeername(
SOCKET s,
struct sockaddr* name,
int* namelen
);
For local IP connected to the remote client or server.
getsockname
The getsockname function retrieves the local name for a socket.
int getsockname(
SOCKET s,
struct sockaddr* name,
int* namelen
);
In both APIs above, IP address (local or remote) is returned in structure "name".
Thanks,