/* It gets the address/port the system picked for this socket (on connected sockets). 
On unconnected client sockets it does not work because the system dynamically chooses a port only when the socket calls a send() call. */
int sock_getmyinfo(SOCKET sock, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen)
/* It gets the address/port the system picked for this socket (on connected sockets). 
On unconnected client sockets it does not work because the system dynamically chooses a port only when the socket calls a send() call. */
int sock_getmyinfo(SOCKET sock, char *address, int addrlen, char *port, int portlen, int flags, char *errbuf, int errbuflen)
{
	struct sockaddr_storage mysockaddr;
	socklen_t sockaddrlen;
	sockaddrlen = sizeof(struct sockaddr_storage);
	if (getsockname(sock, (struct sockaddr *) &mysockaddr, &sockaddrlen) == -1)
	{
		sock_geterror("getsockname()", errbuf, errbuflen);
		return 0;
	}
	return sock_getascii_addrport(&mysockaddr, address, addrlen, port, portlen, flags, errbuf, errbuflen);
}