O'Reilly logo

IPv6 Network Administration by David Malone, Niall Richard Murphy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Programming

If 10 years from now, when you are doing something quick and dirty, you suddenly visualize that I am looking over your shoulders and say to yourself, "Dijkstra would not have liked this," well that would be enough immortality for me.

Edgar Dijkstra

The sockets programming interface is probably the most commonly used interface for writing TCP/IP based applications. The sockets API is largely protocol agnostic, so adding support for IPv6 has proved to be relatively easy. To prevent inconsistencies[1] between the implementations, some standards have been produced to encourage a unified API (RFC 3493 and RFC 3542).

Familiar sockets function calls such as socket, connect, bind, listen and accept all remain unchanged, apart from the introduction of a new address family AF_INET6 that is used instead of AF_INET. IPv6 socket addresses are stored using a struct sockaddr_in6 rather than a struct sockaddr_in; so much is self-explanatory. More interestingly, a struct sockaddr_storage is provided which is large enough to store any protocol address. This is intended to make it easier to write protocol-independent code. Previously, struct sockaddr was sometimes used for this purpose, but the size chosen for this structure was too small on many systems.

Apart from the structures, the main change to the API for IPv6 is the provision of functions for looking up and printing IPv6 hostnames and addresses. The most important of these are getaddrinfo and getnameinfo. These are replacements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required