The following piece of code always prints the output:

The address is INADDR_ANY
The address is IN6ADDR_ANY_INIT




#include
#include
#include
#include
extern int errno;
void main(int argc,char *argv[])
{
struct addrinfo *res=NULL,hints,*temp=NULL;
int rc=0;

memset(&hints,0,sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;

if((rc=getaddrinfo(NULL,"1900",&hints,&res))!=0)
{
fprintf(stderr,"ERROR:%s\n",gai_strerror(rc));
exit(1);
}
temp=res;
while(temp!=NULL)
{
if(temp->ai_family==PF_INET)
fprintf(stdout,"The address is INADDR_ANY\n");
else if(temp->ai_family==PF_INET6)
fprintf(stdout,"The address is
IN6ADDR_ANY_INIT\n");
temp=temp->ai_next;
}

}



Is there a way the order of the output can be changed? i.e I want the
IPv6 address to be reported first.

My expected output is:

The address is IN6ADDR_ANY_INIT
The address is INADDR_ANY

On Solaris and HP-UX, the IPv6 address is reported first. What should
be done to change the order of preference to IPv6 address on AIX ?

Thanks,
Ravindra.