There is also the possibility to use the getpeername() function on a connected socket. Here are some pieces of code:
struct sockaddr_in addr; int address_size; address_size = sizeof(addr); if(getpeername(sd, &addr, &address_size) != -1) { addr.sin_addr.s_addr = ntohl(addr.sin_addr.s_addr); fprintf(stdout, "\nConnected from client %s on source port %u\n\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); fflush(stdout); } Regards Anders On Thu, 17 Jun 2004, Mike Sontum wrote: > > See the demos section in openssl-0.9.7d/demos/ssl/serv.cpp. > This is UNIX oriented answer there is a struct > struct sockaddr_in sa_cli; > that is defined in > struct sockaddr_in { > sa_family_t sin_family; > in_port_t sin_port; > struct in_addr sin_addr; > unsigned char sin_zero[8]; > }; > /usr/include/netinet/in.h > sd = accept (listen_sd, (struct sockaddr*) &sa_cli, &client_len); > printf ("Connection from %lx, port %x\n", > sa_cli.sin_addr.s_addr, sa_cli.sin_port); > > Thanks, > > Mike > > >>> [EMAIL PROTECTED] 6/17/2004 3:40:22 AM >>> > Hi, > > so the question is: when Server accepts client connection, do he get > IP > address of the client for further correspondence. If not how can I get > IP > address of the client connecting to my server? and if yes from where > can I > print out client IP address? > > thankx > > MI > > > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > > User Support Mailing List [EMAIL PROTECTED] > > Automated List Manager [EMAIL PROTECTED] > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List [EMAIL PROTECTED] > Automated List Manager [EMAIL PROTECTED] > ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]