Archived

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

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

This topic is 5703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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