Winsock: AF_INET or AF_INET6

Tell me please, what rule to follow when creating a socket ?

Well, that is, for an example: suppose I need to create a client socket, that is, to connect to a server via TCP, all my MISUSE is in the range between two parameters: this is creating a socket with the AF_INET or AF_INET6 parameter.

Well, that is, for example: there is a provider, he gives me the ip version of v4. Now I just want to send a request to the server, for this I have to find out the IP of the server and create a socket.

The question is, what rule should I follow when choosing the AF_INET or AF_INET6 parameter when creating a socket?

If so, how can you programmatically determine which version of the ip my provider is issuing?

PS:AF_UNSPEC - it is recommended not to use it because of the vulnerability.