I\'ve opened a TCP socket server (I\'ve omitted a few stuff, it is taken from here
sockfd = socket(p->ai_family, p->ai_socktype,
p->ai_p
You can't use the socket to get the server's address before a client connects, because it isn't known.
In principle, a host may have multiple IPs. The IP used for a connection to a server is the one belonging to the interface, through which the connection arrived. Until a connection arrives, it isn't known.
Even if you have only one IP, connections may arrive from within the machine, in which case the address would be 127.0.0.1
.
So the listening socket has no information about the IP.
You'll need to find what interfaces the machine has, and what's their IPs.