I\'m prepping for a simple work project and am trying to familiarize myself with the basics of socket programming in a Unix dev environment. At this point, I have some basic
From the looks of your code you are not doing connect
or accept
on the socket. Until you have done this the data you get from getsockname
is undefined.
I don't think you can meaningfully call getsockname in this context until you've called connect() - the kernel doesn't bind it to a particular port until it needs to (or is told to do so explicitly), and the local address is chosen based on the routing table, and hence the destination.