I know this question seems typical and multiple times answered but I think if you read the details it is not so common (I did not find it).
The poin
You would use getsockname() (http://linux.die.net/man/2/getsockname) to get the IP of the bound socket.
getsockname()
Also answered before, here: C - Public IP from file descriptor