c - Need to understand the structure returned by getaddrinfo() -


i'm trying build simple webserver ip version agnostic.

this sample code snippet

hints.ai_family = af_unspec; // af_inet or af_inet6 force version hints.ai_flags = ai_passive;     // fill in ip me hints.ai_socktype = sock_stream;     if ((status = getaddrinfo(null, "8000", &hints, &res)) != 0){     fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));     exit(0); }    

after populating status, go through each element of linked list "res" till find valid entry, , initialize socket structure.

my question is, in linked list "res" returned getaddrinfo(), separate structures ipv4 , ipv6 loopback addresses? , in case, need create 2 sockets listen , serve ipv4 , ipv6 loopback addresses seperately? or there single structure in "res" linked list can used create socket "magically" listens on both ipv4/v6 loopback addresses?

thank you

my question is, in linked list "res" returned getaddrinfo(), separate structures ipv4 , ipv6 loopback addresses?

you separate results ipv4 (family af_inet) , ipv6 (family af_inet6) addresses. particular arguments, however, should not results bearing loopback address, because you've given specified no node , given ai_passive hint. every struct returned should represent wildcard address.

and in case, need create 2 sockets listen , serve ipv4 , ipv6 loopback addresses seperately?

no, should not need multiple sockets. both ipv4 , ipv6 addresses on machine running dual stack. if want serve both ipv4 , ipv6 clients such machine (and should), sure select ipv6 address. should work clients using either protocol.

or there single structure in "res" linked list can used create socket "magically" listens on both ipv4/v6 loopback addresses?

there's bit of magic involved, it's @ network , protocol levels. ipv6 designed expectation of significant transition period, , therefore has provisions interoperability ipv4.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -