I would like to be able to loop through a list which is a result of the getaddrinfo() function and call connect() using every element of that list until connect() is successful. Unfortunately, even when I specify the AI_ALL | AI_V4MAPPED flags, and an AF_INET6 family, the results are mixed. The first part of the list contains sockaddr_in6 structures, and the second part sockaddr_in structures, so i can’t use them with an AF_INET6 socket.
I know i can create two sockets. I would like to know whether it’s possible to do it with just the AF_INET6 socket.
Here’s the operating system:
> uname -a
> Linux debian 2.6.32-5-amd64 #1 SMP Wed Jan 12 03:40:32 UTC 2011 x86_64 GNU/Linux
You don’t have to worry if it’s an AF_INET or AF_INET6 socket you are creating.
Simply pass the data from the getaddrinfo() call to the socket() call.
e.g.