IPV6 Network Programming
This book tries to outline how to write an IPv6-capable application on a UNIX socket API, or how to update your IPv4 application to be IPv6-capable. The book tries to show portable and secure ways to achieve these goals.
Write Portable Application Programs
There are a large number of platforms that support socket API for network programming. When you write an application on top of socket API, you will want to see your program work on as many platforms as possible. Therefore, portability is an important factor in application programming. As many of you already know, there are many UNIX-like operating systems, as well as non-UNIX operating systems that implement socket APIs. For instance, Windows XP does implement socket API; Mac OS X uses BSD UNIX as the base operating system and provides socket API to the users (Apple normally recommends the use of Apple APIs). So the book tries to recommend portable ways of writing IPv6-capable programs.
Be Security Conscious When Writing Programs
Security is a great concern these days in the Internet—if you are a network administrator, I guess you are receiving tons of spam, email viruses, and vendor advisories every day. To secure the Internet infrastructure, every developer has to take a security stance—to audit every line of code as much as possible, to use proper API, and write a correct and secure code. To achieve this goal, in this book, efforts are made to ensure correctness of the examples. The examples presented in this book are implemented with security stance. Also, the book tries to lead you to write secure programs. For instance, the book recommends against the use of some of the IPv6 standard APIs; unfortunately, there are some IPv6 APIs that are inherently insecure, so the book tries to avoid (and discourage) the use of such APIs.
This book does not try to cover every aspect of IPv6 technology—the book constrains itself to the IPv6-capable programming on top of socket API. There are numerous reading materials on IPv6 technology, so readers are encouraged to read them before starting to work on this book.
Also, the book assumes a certain level of expertise in socket API programming. The book does not try to explain every aspect of socket API programming; please read the material listed in the References for an introductory description to socket API.
Terminology and Portability
This section describes notations and terminologies used in this book. Here we also discuss porting issues of examples when you are using operating systems that are not 4.4BSD variants.
Terminology
System calls and system library functions are usually denoted by UNIX manpage chapters: socket(2) or printf(3). “Nodes” means any IP devices. “Routers” are any nodes that forward packets for others. “Hosts” are nodes that are not routers (however, in this book, we don’t really need to make distinctions between them).
Portability of Examples
The examples in the book compile and run on latest *BSD releases. I tried to make the examples as correct as possible. If you are planning to use the examples on other platforms, here are some tweaks dependent on OS implementations.
Solaris, Linux, Windows XP
struct sockaddr has no sa_len member. Therefore, it is not possible to get the size of a given sockaddr when the caller of the function passed a pointer to a sockaddr. The only ways to work around this problem are:
1. To always pass around the length of sockaddr separately on function calls:
struct sockaddr *sa;
int salen;
foo(sa, salen)
2. To have a switch statement to determine length of sockaddr. With this approach, however, the application will not be able to support sockaddrs with unknown address family.
struct sockaddr *sa;
int salen;
switch (sa->sa_family) {
case AF_INET:
break;
case AF_INET6:
salen = sizeof(struct sockaddr_in6);
break
default:
fprintf(stderr, “not supported\n”);
exit(1);
/*NOTREACHED*/
}
Download: IPV6 Network Programming

0 comments:
Post a Comment