I did a little checking on the internet. getsockname returning 0.0.0.0 is quite common as follows:
Yes, if you bind it to a LOOPBACK , u have to specify INADDR_LOOPBACK. Otherwise it attaches itself to 0.0.0.0 which represents all the network interfaces available. I was facing the same problem, while issuing getnameinfo() call.
Bottom line is that most of the time unless you specifically bound the socket to an interface, getsockname returns 0.0.0.0 meaning all interfaces. I have tried the API I mentioned previously (customizeIamGetIfAddress) and becuase in this API you pass a specific interface (ethernet is eth0 and wireless is wln0 you get an actual IP address. Again this is due to you requesting a specific interface.