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]
# 1 Re: Get IP Address from a socket.
Try CAsyncSocket::GetPeerNameEx();
cipher1024 at 2007-11-9 13:51:57 >
# 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!!!!!!!
Guidosoft at 2007-11-9 13:52:57 >
# 3 Re: Get IP Address from a socket.
So sorry shud'vw asked that first
cipher1024 at 2007-11-9 13:53:56 >
# 4 Re: Get IP Address from a socket.
So do you know how to do it?
Guidosoft at 2007-11-9 13:55:02 >
# 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,
nkhambal at 2007-11-9 13:56:01 >