Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
51
Добавлен:
11.04.2015
Размер:
22.9 Mб
Скачать

406 Understanding IPv6, Second Edition

The function prototype for freeaddrinfo() is the following:

void freeaddrinfo(

struct addrinfo FAR *ai

);

Address-to-Name Translation

A reverse lookup can be performed by using another new sockets function, getnameinfo(). To use this API, a socket address structure is provided. The function prototype for getnameinfo() is the following:

int getnameinfo(

IN const struct sockaddr FAR *sa, IN socklen_t salen,

OUT char FAR *host, IN size_t hostlen, OUT char FAR *serv, IN size_t servlen, IN int flags

);

It contains the address and port in question. This can be either an IPv4 or IPv6 socket address structure because the length is also provided.

Additionally, buffers are provided to receive the node name and service name associated with that address, and the flags field can be used to change the default behavior of the API. The lengths of these buffers are provided in the call, and constants are defined (NI_MAXHOST, NI_MAXSERV) to aid the application in allocating buffers of the maximum size required.

The flags adjust the behavior as follows:

NI_NOFQDN Setting the NI_NOFQDN flag results in returning only the node name (not the fully qualified domain name, or FQDN) for local hosts.

NI_NUMERICHOST Setting this flag results in returning the numeric form of the host’s address instead of its name.

NI_NAMEREQD Setting the NI_NAMEREQD flag results in returning an error if the name cannot be located.

NI_NUMERICSERV Setting NI_NUMERICSERV results in returning the numeric port number instead of the service name.

NI_DGRAM Setting this flag specifies that the service is a datagram service, causing a search for a User Datagram Protocol (UDP) service—instead of a Transmission Control Protocol (TCP) service.

Соседние файлы в папке Lecture 2_10