![]() | ![]() | ![]() | IPv6 API |
In a way, things have become a lot simpler, there is now sockaddr_storage and addrinfo. These two structures should do the majority of what you need.
struct sockaddr_storage {
u_char ss_len;
u_char ss_family;
u_char padding[128-2];
};
The main difference between this structure and the old one is that it much larger so it can hold the larger addresses.
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
struct sockaddr *ai_addr;
char *ai_canonname;
struct addrinfo *ai_next;
};
Notice that the structure looks a little like the old struct hostent structure but with the additional protocol line and a pointer to the same time.
Most functions return a singularly linked list of these structures. You traverse the list by moving through the ai_next items until you hit null.
This first set of functions are similar to the ones used in IPv4. In fact these functions can be used for IPv4 instead of the regular ones. The advantage is that most code can use IPv4 or IPv6 and it will work fine, which was a major goal of the API designers.
The first function is getaddrinfo which is used to do the work that getipnodebyname and getservbyname can do. In other words the function does the name to address translation. The good thing is that you can do hostname and service name translation at the same time, it returns a list and it is thread safe unlike most of the old functions.
![]() | ![]() | ![]() | IPv6 API |