Q:

On server side, get the server IP to which client is connected

Server has multiple interfaces. Server is bound to 0.0.0.0 which means it is listening on all the interfaces it has. So, client can connect using any one of these server IPs.
So, on the server side how to get the IP to which client is connected.

A:

Use getsockname() on the socket returned by accept(), it will be bound to the local address that your server is using to communicate with the accepted client.
NAME
     getsockname — get socket name
LIBRARY
     Standard C Library (libc, -lc)
SYNOPSIS
     #include <sys/types.h>
     #include <sys/socket.h>

     int
     getsockname(int s, struct sockaddr * restrict name,
     socklen_t * restrict namelen);

DESCRIPTION
     The getsockname() system call returns the current name for the specified
     socket.  The namelen argument should be initialized to indicate the
     amount of space pointed to by name.  On return it contains the actual
     size of the name returned (in bytes).

