Getnameinfo – Comtrol eCos User Manual

Page 523

Advertising
background image

Chapter 38. TCP/IP Library Reference

getnameinfo

GETNAMEINFO(3)

System Library Functions Manual

GETNAMEINFO(3)

NAME

getnameinfo - address-to-nodename translation in protocol-independent

manner

SYNOPSIS

#include

<

sys/types.h>

#include

<

sys/socket.h>

#include

<

netdb.h>

int

getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host,

size_t hostlen, char *serv, size_t servlen, int flags);

DESCRIPTION

The getnameinfo() function is defined for protocol-independent address-

to-nodename translation.

Its functionality is a reverse conversion of

getaddrinfo(3), and implements similar functionality with

gethostbyaddr(3) and getservbyport(3) in more sophisticated manner.

This function looks up an IP address and port number provided by the

caller in the DNS and system-specific database, and returns text strings

for both in buffers provided by the caller.

The function indicates suc-

cessful completion by a zero return value; a non-zero return value indi-

cates failure.

The first argument, sa, points to either a sockaddr_in structure (for

IPv4) or a sockaddr_in6 structure (for IPv6) that holds the IP address

and port number.

The salen argument gives the length of the sockaddr_in

or sockaddr_in6 structure.

The function returns the nodename associated with the IP address in the

buffer pointed to by the host argument.

The caller provides the size of

this buffer via the hostlen argument.

The service name associated with

the port number is returned in the buffer pointed to by serv, and the

servlen argument gives the length of this buffer.

The caller specifies

not to return either string by providing a zero value for the hostlen or

servlen arguments.

Otherwise, the caller must provide buffers large

enough to hold the nodename and the service name, including the terminat-

ing null characters.

Unfortunately most systems do not provide constants that specify the max-

imum size of either a fully-qualified domain name or a service name.

Therefore to aid the application in allocating buffers for these two

returned strings the following constants are defined in

<

netdb.h>:

#define NI_MAXHOST

MAXHOSTNAMELEN

#define NI_MAXSERV

32

The first value is actually defined as the constant MAXDNAME in recent

versions of BIND’s

<

arpa/nameser.h> header (older versions of BIND define

this constant to be 256) and the second is a guess based on the services

419

Advertising