How to switch the IP stack from IPv4 to IPv6 at the run time in mosquitto library.
there is no explicit way to switch bewteen IPv4 and IPv6 in the mosquitto client library. The network stack to be used will depend on the result of the host resolution using getaddrinfo system call. The client library will iterate over the result of the host resolve and try to use the resolved connection type.
If you resolve configruation will respond with an IPv6 address as the first result the client library will try to use this ipv6 target address. If this fails the next resolv result (which may be the IPV4 address will be used).
In default configuration all modern system with IPv6 enabled will have a IPv6 precedence configured. As specified in the RFC3484. If a hostname can be resolved to an IPv6 and an IPv4 address the IPv6 address will be preferred and returned as first result.