Previous Next Table of Contents

6. IPv6 application information

6.1 How to write for and port to IPv6

Writing software for IPv4/IPv6 platforms

Matti Aarnio asked:

"If possible, tell also how to do software for mixed environments.
That is, software that can be compiled both on IPv4-only systems,
and also on IPv6 with all these new fancy widget routines.
I bet MOST of the applications fall on this category, at least for
now...  (And those systems don't have NRL libraries in them.)"

Philip Blundell gives us this answer:

"There are really two problems here.  Firstly, how to make software that
can be compiled on both new systems with IPv6 capability, and old
IPv4-only systems.  And secondly, once you've compiled your code, there is
the issue of making sure that the same binaries will work regardless of
whether IPv6, IPv4, or both are supported. 

To deal with the second problem first, the best thing to do is to use
getaddrinfo() for all your name lookups and so on.  This hands you back
both an address family and an address structure; you can then pass the
returned address family straight to socket() to create the right sort of
socket.  If the host you asked for has an AAAA record, you'll get back
AF_INET6 and a struct sockaddr_in6, otherwise if it has an A record you'll
get back AF_INET and a struct sockaddr.  getaddrinfo() and its counterpart
getnameinfo() are in glibc 2.1.

By using these calls, your code can be more-or-less entirely unaware of
the address family in use, and you can avoid using struct
sockaddr_in/struct sockaddr_in6.  Thus your code will be equally happy in
IPv6-only, IPv4-only and mixed environments.  Take a look at the
inet6-apps sources for examples of how to do this sort of thing. 

The first problem is a bit more of a nuisance.  Old versions of the C
library don't have getaddrinfo(), though it is provided in libinet6.  You
will probably need to provide a compile-time switch and lots of #ifdefs to
select between getaddrinfo() and the old name-lookup calls.

BTW, getaddrinfo() is a POSIX function, rather than an NRL specific, so it
ought to be safe to use in portable code."

6.2 Applications under IPv6

Is there an IPv6-porters mailing list?

Yes. Thanks to for pointing this out. Subscribe via

Previous Next Table of Contents