getsockname() returns the address that the socket was bound to. If it was bound to INADDR_ANY, getsockname() will stubbornly return INADDR_ANY (and someport - that one is valid). Subsequent connection attempts to INADDR_ANY:someport will fail with winsock. Actually, it doesn't make even sense to connect to INADDR_ANY at all (where is the socket connecting to? To a random interface of the host?), so this is just a straight-up change, without platform-specific ifdefing.
Use loopback instead of INADDR_ANY.