Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getnameinfo() - get name of the communications partner

&pagelevel(4)&pagelevel

#include <sys/socket.h>
#include <netdb.h>

int getnameinfo (struct sockaddr *sa, size_t salen, char *host, size_t hostlen,
                 char *serv, size_t servlen, int flags);

Description

The getnameinfo() function returns the name assigned to the IP address and port number specified in the call as a text string. The values are determined either from a DNS server via the DNS Resolver integrated in SOCKETS(BS2000) or using system-specific tables.

The sa parameter is a pointer to a sockaddr_in structure which contains the IP address and port number. The actual format of the sockaddr structure depends on the address family involved and is described in section "Socket addressing". The exact format of * sa is determined by the domain in which communications takes place. salen indicates the length of the structure.

If getnameinfo() is executed successfully, host and serv are pointers to two areas containing the corresponding null-byte-terminated socket host name and service name respectively. The lengths of the areas are specified in hostlen and servlen respectively. These areas must be large enough to store the socket host name or service name (including the null byte). If the value 0 is specified for hostlen or servlen when getnameinfo() is called, this indicates that no socket host name or no service name is to be returned.

The maximum lengths of the socket host name and service name are defined in <netdb.h>:

#define NI_MAXHOST 1025
#define NI_MAXSERV 32

The flags parameter changes how getnameinfo() is executed. Normally, the fully-qualified domain name of the host is determined from the DNS and returned. Depending on the value of flags, a distinction is made between the following cases:

NI_NOFQDN

Only the host name part of the full DNS name (socket host name) is returned.

NI_NUMERICHOST

The numeric host name is returned in printable format after address conversion. The same applies if it is impossible to determine the host name in the DNS or using local information and NI_NAMEREQD is not set.

NI_NAMEREQD

An error is reported if the host name cannot be determined in the DNS.

NI_NUMERICSERV

The port number is returned in printable format instead of the service name.

Return value

0:

If successful

<> 0:

If errors occur

Errors

EAFNOSUPPORT

The function is not supported on this system. See also the section "Dependencies on the BS2000 transport system BCAM transport system" for more information.

EINVAL

Invalid address family specified in the sa parameter, or the lengths of the output areas host and/or serv are too small.