Archived

This topic is now archived and is closed to further replies.

bishop_pass

TCP/IP: Server calls accept(); how do I get the ip of the client?

Recommended Posts

bishop_pass    109
I''ve been wading through some docs, and I''m trying to find a quick answer to this. My server calls accept() and gets a client. I want the ip address of the client. This data must be available somewhere. Where is it?

Share this post


Link to post
Share on other sites
Dean Harding    546
When you call accept, you also pass it a pointer to a sockaddr structure. This receives the address of the connecting client, so you can do something like this:


SOCKADDR_IN addr;
int len = sizeof(SOCKADDR_IN);

s = accept( listen_socket, (sockaddr *)&addr, &len );
cout << "Connection received from: " << inet_ntoa( addr.sin_addr ) << endl;



codeka.com - Just click it.

Share this post


Link to post
Share on other sites